KEMBAR78
1b Linux Basics | PDF | File System | Linux
0% found this document useful (0 votes)
88 views51 pages

1b Linux Basics

Linux is a fully-networked 32/64-bit operating system created by Linus Torvalds in 1991. It uses a hierarchical file system and includes many open source tools like sed, awk, grep, and compilers. Users are assigned to groups which control permissions to access files. The kernel manages hardware resources and processes run in either the foreground or background.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views51 pages

1b Linux Basics

Linux is a fully-networked 32/64-bit operating system created by Linus Torvalds in 1991. It uses a hierarchical file system and includes many open source tools like sed, awk, grep, and compilers. Users are assigned to groups which control permissions to access files. The kernel manages hardware resources and processes run in either the foreground or background.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 51

Linux basics

25 ottobre 2018 1
Summary

 What is Linux?
 Linux basics
 Using Linux
What is Linux?

 A fully-networked 32/64-bit Unix-


like operating system
► UnixTools Like sed, awk, and grep
► Compilers Like C, C++, Fortran, Smalltalk
► Network Tools Like telnet, ftp, ping

 Multi-user, Multitasking,
Multiprocessor
 It can have the X Windows GUI
 Includes the Source Code
What is Linux?

 Where did it come from?


► Linus Torvalds created it with assistance
from programmers around the world
► First posted on Internet in 1991
► Linux 1.0 in 1994; 2.2 in 1999
► Today used on 7-10 million computers
► Open source: thousands of programmers
working to enhance it
What is Linux?

 How do you get it?


► Download it from the internet
► From a “Distribution” (e.g. RedHat, Debian,
Backtrack)
• Linux kernel
• X Windows system and GUI
• Web, e-mail, FTP servers
• Installation and configuration support
• 3rd party apps
• Hardware support
What is Linux?

 Why is it significant?
► Growing popularity
► Powerful
• Includes a large number of network/hacking
tools
► It's “free”
• Licensed under GPL
• Vendors are distributors who package Linux
Linux basics
 Users and groups
► Users are identified by user identifications
(UIDs), each of which is associated with an
integer in the range of 0 to 4.294.967.295
(hex FFFFFFFF). Users with UID=0 are
given superuser privileges
► Users are placed in groups, identified by
group identifications (GIDs). Each GID is
associated with an integer in the range
from 0 to 4.294.967.295
► Use id to display your user and group
information
Linux basics

 Users and groups


► Groups define functional
areas/responsibilities
► They allow a collection of users to share
files
► A user can belong to multiple groups
► You can see what groups you belong to
using the groups command
Linux basics

 The Linux system

User commands
Shell
Kernel File Systems
Device Drivers
Hardware
Linux basics

 The Linux system


► User commands include executable
programs and scripts
► The shell interprets user commands. It is
responsible for finding the commands and
starting their execution. Several different
shells are available. Bash is popular
► The kernel manages the hardware
resources for the rest of the system
Linux basics

 The Linux file system


Linux basics

 The Linux file system


► Linux files are stored in a single rooted,
hierarchical file system
• Data files are stored in directories (folders)
• Directories may be nested as deep as needed
• Directories can be mount points where to attach
a different file system, either local or remote
Linux basics

 The Linux file system


► Naming files
• Files are named by naming each containing
directory starting at the root ( / )
• This is known as the pathname
• e.g. /etc/passwd
► One directory is designated as the current
working directory
• if you omit the leading / then path name is
relative to the current working directory
• Use pwd to find out where you are in the file-
system
Linux basics

 The Linux file system


► Some file names are special
• / the root directory (not to be confused with the
root user)
• . the current directory
• .. the parent (previous) directory
• ~ my home directory
► Examples
• ./a same as a
• ../jane/x go up one level then look in
directory jane for file x
Linux basics

 The Linux file system


► Special files (continued)
• /etc/passwd contains all users and
passwords, if /etc/shadow is not used
(must be readable by everyone)
• /etc/shadow contains all users and
passwords in newer distributions
(only root users can read it)
Linux basics

 The Linux file system


► Special directories
• /home all users' home directories are stored
here
• /bin /usr/bin system commands
• /sbin /usr/sbin commands used by
sysadmins
• /etc all sorts of configuration files
• /var logs, spool directories etc.
• /dev device files
• /proc special system files
Linux basics

 Shells
► An interface between the Linux system and
the user
► Used to call programs and commands
► An interpreter
► Powerful programming language
• Shell scripts
► Many available
• bsh, ksh, csh, bash, tcsh
Linux basics

 Another definition of a shell


►A shell is any program that takes input from
the user, translates it into instructions that
the operating system can understand, and
conveys the operating system's output
back to the user
• i.e. Any user interface
• Character Based vs Graphics Based
Linux basics

 Shell is not an integral part of OS


► UNIX among first to separate
► GUI is not required
• Servers usually do not have a graphic GUI
► Default shell can be configured
Linux basics

 Environment variables
► Environment variables are global settings
that control the function of the shell and
other Linux programs. They are sometimes
referred to global shell variables.
► Examples:
• VAR=/home/fred/doc
• export TERM=ansi
• SYSTEMNAME=`uname -n`
Linux basics

 Using environment Variables


► echo $VAR
► cd $VAR
► cd $HOME
► echo “Running on $SYSTEMNAME”

 Displaying
► set
► export

 Vars can be retrieved by scripts or


programs
Linux basics

 Some important Environment


variables
► HOME
• Your home directory (often abbreviated as “~”)
► TERM
• The type of terminal you are running (for
example vt100, xterm, and ansi)
► PWD
• Current working directory
► PATH
• List of directories to search for commands
Linux basics

 PATH environment variable


► Controls where commands are found
• PATH is a list of directory pathnames separated
by colons. For example:
PATH=/bin:/usr/bin:/usr/X11R6/bin:/
usr/local/bin:/home/scully/bin
• If a command does not contain a slash, the
shell tries finding the command in each
directory in PATH. The first match is the
command that will run
Linux basics

 BASH history
► The user's home directory contains the
shell history file
► .bash_history or .sh_history
► It contains the last typed commands
► It could contain usernames/passwords in
cleartext if the users typed them on the
command line
Linux basics

 BASH history

► How many .bash_history files are there in a


given system?
Linux basics

 File permissions
► Every file
• Is owned by someone
• Belongs to a group
• Has certain access permissions for owner,
group and others
• Default permissions determined by umask
► There are no “negative” permissions.
• i.e. it's not possibile to assign read permission
of a file to all users of a group but one: the file is
either readable by all users in the group or by
none of them
Linux basics

 File permissions (continued)


► Every user has a UID (login name), GID
(login group) and membership of a
“groups” list
• The UID is who you are (name and number)
• The GID is the initial “login group” you normally
belong to
• The groups list is the file groups you can
access via group permissions
Linux basics

 File permissions (continued)


► Linux provides three kinds of permissions
• Read - users with read permission may read
the file or list the directory
• Write - users with write permission may write to
the file or new files to the directory
• Execute - users with execute permission may
execute the file or lookup a specific file within a
directory
Linux basics

 File permissions (continued)


► The long version of a file listing (ls -l) will
display the file permissions
► e.g. -rwxrwxrwx

- rwx rwx rwx


Directory flag Owner Group Other
(d=directory permissions permissions permissions
l=link)
Linux basics

 Linux device handling


► Devices are the way linux talks to the world
► Devices are special files in /dev directory
► Each /dev file has a major and minor
number
• Major defines the device type
• Minor defines device within that type
• Drivers register a device type
Linux basics

 File Systems
► Linux supports many different types of file
systems
► Most commonly, ext2, ext3, reiserFS
► Other file systems: ntfs (WinNT), ISO9660
(CD-ROM), vfat (Win9x), and many others
Linux basics

 File Systems
► mount – mounts a file system that lives on
a device to the main file tree
► /etc/fstab used to establish boot time
mounting
Linux basics

 Processes
► Processes are created in a hierarchical
structure whose depth is limited only by the
virtual memory available to the virtual
machine
► A process may control the execution of any
of its descendants by suspending or
resuming it, altering its relative priority, or
even terminating it
Linux basics

 Processes (continued)
► Termination of a process by default causes
termination of all its descendants;
termination of the root process causes
termination of the session
► Linux assigns a process ID (PID) to the
process
Linux basics
 Processes (continued)
► Foreground
• When a command is executed from the prompt
and runs to completion, at which time the
prompt returns, it is said to run in the
foreground
► Background
• When a command is executed from the prompt
with the token “&” at the end of the command
line and the prompt immediately returns while
the command continues, it is said to run in the
background
Linux basics

 Processes (continued)
► Daemons
• Background processes for system
administration are referred to as “daemons”
• These processes are usually started during the
boot process
• The processes are not assigned any terminals
since normally they are not interactive
Linux basics

 Processes (continued)
► PID
• A process ID is a unique identifier assigned to a
process while it runs
• Each time you run a process, it has a different
PID (it takes a long time for a PID to be reused
by the system)
• You can use the PID to track the status of a
process with the ps command or the jobs
command
• You can terminate a process with the kill
command followed by its PID
Linux basics

 Questions
► Is a shell the same thing as an MS-DOS
command prompt?
► Where are the users' home directories
located?
► Where are password files located?
Using Linux

 Important note
► Do not login as root unless you have to
► Root is the system superuser
• Normal protection mechanisms can be
overriden
• Careless use can cause damage
• Has access to everything by default
Using Linux

 Getting help
► The Linux equivalent of HELP is man
(manual)
► Use man -k <keyword> to find all
commands with that keyword
► Use man <command> to display help for
that command
• The output is presented one page at a time
Using Linux

 Linux command basics


► To execute a command, type its name and
arguments at the command line
► e.g. ls -l /etc
• ls command name
• -l option (flag)
• /etc argument
Using Linux

 UNIX concept of “standard files”


► Standard input (where a command gets its
input) – default is the terminal
► Standard output (where a command writes
its output) - default is the terminal
► Standard error (where a command writes
error messages) – default is the terminal
Using Linux

 Redirecting output
► The output of a command may be sent
(piped) to a file
• ls -l > output
 Redirecting input
► The input of a command may come (be
piped) from a file
• wc < input
Using Linux

 Connecting commands with pipes


► The output of one command can become
the input of another
► e.g. ps -a | grep netscape | wc
-l
• “|” is used to separate stages
• The output of the ps command is sent to grep
• grep takes input and searches for “netscape”,
passing these lines to wc
• wc takes this input and counts the lines, its
output going to the console
Using Linux

 Command options
► Command options allow you to control a
command to a certain degree
► Conventions
• Usually begin with a single dash and are a
single letter (“-l”)
• Sometimes have double dashes followed by a
keyword (“--help”)
• Sometimes follow no pattern at all
Using Linux

 Common commands
► pwd - print (display) the working directory
► cd <dir> - change the current working
directory to <dir>
► ls - list the files in the current working
directory
► ls -l - list the files in the current working
directory in long format
► cp <fromfile> <tofile> - copy from
the <fromfile> to the <tofile>
Using Linux

 Common commands (continued)


► mv <fromfile> <tofile> -
move/rename the <fromfile> to the <tofile>
► rm <file> - remove the file named <file>

► mkdir <newdir> - make a new directory


named <newdir>
► rmdir <dir> - remove an (empty)
directory named <dir>
► who – Lists who is currently logged on to
the system
Using Linux

 Common commands (continued)


► whoami – reports which user you are
currently logged on as
► ps – lists your processes on the system

► ps aux – lists all the processes on the


system
► echo “a string to be echoed” -
echoes a string (or list of arguments) to the
terminal
Using Linux

 Common commands (continued)


► find – Searches a given file hierarchy
specified by path, finding files that match
the criteria given by expression
► grep – Searches files for one or more
pattern arguments. It does plain string,
basic regular expression, and extended
regular expression searching
► kill – sends a signal to a process or
process group
Using Linux

 Common commands (continued)


► su <accountname> – switch user
accounts. You will be prompted for a
password. When this command completes,
you will be logged into the new account.
Type exit to return to the previous account
► su – Switch to the root user account. Do
not do this lightly
Using Linux

 Questions
► Who is root?
► What does the man command do?

► What is the difference between cd goofy


and cd /goofy?

You might also like