linux filesystem structure - politecnico di milano · federico reghenzani 4/19 dipartimento di...
TRANSCRIPT
Titolo presentazionesottotitolo
Milano, XX mese 20XX
Piattaforme Software per la Rete
Linux and BASH Introduction
A.A. 2016/17Federico Reghenzani
Federico Reghenzani 2/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Outline
1) Linux filesystem structure
2) The Linux Prompt
3) Basic commands
4) Permissions
Federico Reghenzani 4/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Linux Filesystem Layout
● Files and directories are structured as a tree
● Unlike Windows, the tree structure is not dependent on disk partitioning
● The root of the tree is identified by / character
● Directories are preceded by a slash and they compose the path:
– /directory1/directory2/file.txt
Federico Reghenzani 5/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Linux Filesystem Layout
/
bin boot dev etc home lib lost+found mnt
opt proc root sbin tmp usr var
william federico lara
bin include ...
Federico Reghenzani 6/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Everything in Linux is a file
● Files are files
● Directories are files containing a list of files
● I/O devices are special files (usually located under /dev)
● Sockets are files (/proc/net)
● Named pipes are files
Federico Reghenzani 8/19
Dipartimento di Elettronica, Informazione e Bioingegneria
The Linux Prompt
In order to modify the prompt, you have to change the PS1 environment variable
Federico Reghenzani 9/19
Dipartimento di Elettronica, Informazione e Bioingegneria
How to execute a command?
● Using an absolute path:
– Example:
● Using a relative path:
– Example:
● Using directly its name if the executable directory is in the PATH environmental variable
– Example:
●
/path/to/somewhere/$ /usr/bin/df
/usr/bin $ ./df
/path/to/somewhere/$ df
Federico Reghenzani 10/19
Dipartimento di Elettronica, Informazione e Bioingegneria
The PATH environmental variable
● The PATH variable specifies where executables are located
● When you type a command that is not a built-in command of the shell, it searches in the directories specifies in the PATH variable the executable
● tells you where is the binary
which command
Federico Reghenzani 12/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Help
● If you don’t know what a command is:
–
–
– Search engines are your friends!
command --help
man command
Federico Reghenzani 13/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Basic commands
●
– Write parameters to standard output
●
– List files in the current directory or in [directory] if specified
●
– Change the current working directory to path (it may be realtive or absolute)
●
– Print the working directory
echo [param1 param2 ...]
ls [directory]
cd path
pwd
Federico Reghenzani 14/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Basic commands
●
– Concatenate files and print to standard output
●
– Copy the file source to destination (if copying a directory you have to add -r option)
●
– Move or rename a file or a directory
●
– Remove a file (if removing a directory, you have to add -r option)
cat [file1 file2 ...]
cp source destination
rm file
mv source destination
Federico Reghenzani 15/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Basic commands
●
– Create a link named link_name that points to destination. If -s is specified, the link is symbolic.
●
– Create a new directory
●
– Remove an empty directory
ln [-s] destination link_name
mkdir directory
rmdir directory
Federico Reghenzani 17/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Permission classes and modes
● Every file is identified by three classes of permission:
– User
– Group
– Other
● Every permission class has three permission mode:
– Read 22=4
– Write 21=2
– Execute 20=1
Federico Reghenzani 18/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Permissions
● They are common reported as
– Examples:● rwxr-xr-x: Owner R,W,X; Group R,X; Other R,X● r-x-w----: Owner R,X; Group W; Other -● rw-------: Owner R,W; Group -; Other -
● Or using the three-digits numerical values XXX
– Examples:● 755: Owner R,W,X; Group R,X; Other R,X● 520: Owner R,X; Group W; Other -;● 600: Owner R,W; Group -; Other -;
rwxrwxrwx
Federico Reghenzani 19/19
Dipartimento di Elettronica, Informazione e Bioingegneria
Change permissions
●
– Assign the permission mode to file_name. mode can be expressed as:
Numerical value, e.g. 755 Symbolic name, e.g. +x, +r, -r, etc. u,g,o can be used to select classes, e.g. u=rwx, g=rx
●
– Change the owner of the file
chmod mode file_name
chown user[:group] file_name