Introduction Emanuele Valea <valea@lirmm.fr> LIRMM CNRS / Université de Montpellier
Course Outline • UNIX operating system: an introduction • Basic commands • Shell • Tools and advanced commands • Shell scripts
Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands
Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands
How to start a session • To begin a session: login: Password: • To end a session: CTRL-d exit logout BE CAREFUL! Unix is case sensitive
Connection to the system • If Linux is installed on your machine: • Just turn on your PC! • If Linux is installed on a remote server: • VNC • SSH • -X it allows graphical interface
Connection to the system: SSH Unix Server Your PC
Connection to the system: SSH • If your PC runs Linux or Mac: • From your terminal simply run: • ssh [-X] [<username>@]<hostname> • -X it allows graphical interface • If your PC runs Windows, you must use external programs: • PuTTY • MobaXterm
Connection to the system: VNC VNC Viewer VNC Server
VNC Server (under Linux) • Connect to the VNC Server using SSH • Run the server: • vncserver – geometry 1280x1024 – depth 24 • For the first execution you have to enter a password (that will be used to authenticate the client) • It will show a number (for instance “:3”) that represents the display number
VNC Viewer • Just run the VNC viewer • Put the address of the server, including the display number • Example: <hostame>:<display_number> • Put your username • Use the password you configured in the server
VNC Server (some hints) • Use: • vncserver – kill :display • to kill the server for the specified display • Example: • vncserver – kill :3 • Use vncpasswd to change the password
Connection to the system • Try for yourselves!
Basic characteristic • Multiuser: for each user: • username • uid There is the • gid special user • password “ root ” • Multiprocess
Command syntax in UNIX • command [-options] [arguments] • It is possible to execute more than one command using the character “ ; ” command1 ; command2 ; ... Commands are executed one after the other
Manual • All Unix commands are documented: • man <command> • apropos <topic> • whatis <command> • All man pages can be easily found on the internet!
Getting help • One thing to remember: • If I have a problem, it is VERY LIKELY that someone has already solved it. • The first place where you will find solutions, are forums on the internet • Example: Stack Overflow, Stack Exchange, ecc …
Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands
File System • Features: • Hierarchic • Directory-based File System • Uniform (disk, directory, file) • Hard link (same file with different names) • Soft link (i.e., shortcut) • File permissions
File System Hierarchy bin dev etc bin sbin etc / lib adm include spool tmp lib tmp var man usr local
Directory handling • ls • It shows the content of the current (or work) directory • cd <dir> • It changes the current directory • pwd • Print Work Directory • mkdir <dir> • It creates a directory • rmdir <dir> • It removes a directory (dir must be empty)
Directory handling • The father of a directory is called ‘..’ • Example: cd .. go back to the upper level in the directory tree. • The list of files and directories of the directory itself is called ‘.’ • mkdir /<dirname> creates a directory in the root directory • mkdir ./<dirname> creates a sub-directory in the work directory
File names The name of the file can be a sequence of any characters • • A file is called hidden file when its name starts with ‘.’ • Special characters (for the shell): • / \ “ ' * ; ? [ ] ( ) ~ • ! $ { } < > # @ & | <space> • To select a file that is not in the current directory it is necessary to specify the path: • Absolute path: /dir1/dir2/file • Relative path: subdir1/subdir2/file
Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands
File handling • cp [-fir] src1 src2 ... dest • To copy one or more files • rm [- fir] file1 file2 … • To delete one or more files • mv [-fi] file1 file2 ... dest • To move (or rename) one or more files
File handling (cont.) • Options: • -f it does not ask for confirmation • -i it asks for confirmation (for each file) • -r it works recursively on every file in sub-directories
File permission modes • 3 permission modes: • read (r) • write (w) • execute (x) • 3 user categories: • user (u): the owner • group (g) • others (o)
Directory permission modes • Permission modes for files have different meanings: • x: the possibility to execute the file • r: the possibility to read the file • w: the possibility to modify the file • Permission modes for directories: • x: the possibility to enter the directory • r: the possibility to show the list of files • w: the possibility to create and remove files
How to change the permissions • To change the permission modes of the file: chmod [-R] mode file • The permission can be specified: • as octal value: User Group Other 4 2 1 4 2 1 4 2 1 r w x r w x r w x • as symbolic string: • +, -, = • u(ser), g(roup), o(ther), a(ll) • r, w, x
How to change the permissions (cont.) • Examples: • chmod 777 filename • chmod +gx filename
Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands
ls • List directory contents • ls [-options] [file ...] • Options: • -a: do not ignore entries starting with . • -l: use a long listing format • -g: like -l, but do not list owner • -r: reverse order while sorting • -t: sort by modification time • -R: list subdirectories recursively
ls - example • # ls -alg ~/tmp total 84 drwx------ 5 maino staff 512 Sep 1 16:14 . drwxr-xr-x 19 maino staff 1024 Sep 6 09:06 .. -rw-r--r-- 1 maino staff 1240 Jan 21 1992 AA.readme drwxr-x--- 2 maino staff 512 May 22 14:08 examples -rw------- 1 maino staff 2416 Jun 30 15:24 gendata.c -rw------- 1 maino staff 332 Jun 18 15:29 local.c drwxr-xr-x 2 maino staff 512 May 22 14:08 man -rw-r----- 1 maino staff 27930 Mar 12 23:19 new.tex -rw------- 1 maino staff 28077 Mar 12 22:52 numer.tex -rw-r----- 1 maino staff 70 Jun 2 18:00 prova.tex -rw-r----- 1 maino staff 1364 May 6 14:20 random.c -rw-r----- 1 maino staff 62 May 6 14:21 random.h drwx------ 2 maino staff 512 May 25 14:36 testprof
Text file analysis • Using a text editor (e.g. vi, emacs, gedit) • cat file1 file2 … • Writes the contents of all the files listed to the screen • head [- n] file … • output the first n lines of the file • Default: n=10
Text file analysis • tail [-n] [+n] [- f] file … • Output the last part of the file: • -n: last n lines, instead of the last 10 • +n: all but the first n lines • -f: output appended data as the file grows
Text file analysis • pg file ... • more file ... • less file ...
Text file analysis • During the visualization: • space next page • CR next line • b previous page • /pattern next page with search pattern • ?pattern previous page with search pattern • q quit
File size and available space • df [-k] [drive ...] • It shows how much free space is left on your system • -k: KB is used (instead of blocks of 512 bytes) • du [-aks ] <directory> … • It prints out the amount of space occupied by a dir • -a: detail report for each file • -s: it recourses into any subdirectories and prints only a summary • -k: KB is used (instead of blocks of 512 bytes)
df: example • $ df • Filesys. 1024-bl. Used Av. Cap. Mnt • /dev/hda3 199270 182354 6625 96% / • /dev/hda1 61060 20967 36939 36% /usr • /dev/hda4 199271 147953 41027 78% /home/pc
Finding a file • find dir expression • search for files in a directory hierarchy • find /users -name core
Finding a file • -name pattern • Base of file name • Caveat: use ‘ pattern ’ for regular expressions • -type type • File type = b(lock), c(haracter), d(irectory), l(ink), f(ile), s(ocket) • -user username / -group groupname
File Comparison • cmp file1 file2 • compare two files byte by byte • comm [-123] file1 file2 • compare two sorted files line by line • It generates 3 columns: • in-file1-only in-file2-only common-lines • -1 suppress lines unique to FILE1 • -2 suppress lines unique to FILE2 • -3 suppress lines that appear in both files
File Comparison • diff [-options] file1 file2 • compare files line by line
time • time command • run programs and summarize system resource usage • Example: • time ls -la
wc • wc file • Print the number of newlines, words, and bytes in files
Recommend
More recommend