introduction
play

Introduction Emanuele Valea <valea@lirmm.fr> LIRMM CNRS / - PowerPoint PPT Presentation

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


  1. Introduction Emanuele Valea <valea@lirmm.fr> LIRMM CNRS / Université de Montpellier

  2. Course Outline • UNIX operating system: an introduction • Basic commands • Shell • Tools and advanced commands • Shell scripts

  3. Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands

  4. Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands

  5. 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

  6. 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

  7. Connection to the system: SSH Unix Server Your PC

  8. 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

  9. Connection to the system: VNC VNC Viewer VNC Server

  10. 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

  11. 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

  12. 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

  13. Connection to the system • Try for yourselves!

  14. Basic characteristic • Multiuser: for each user: • username • uid There is the • gid special user • password “ root ” • Multiprocess

  15. 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

  16. Manual • All Unix commands are documented: • man <command> • apropos <topic> • whatis <command> • All man pages can be easily found on the internet!

  17. 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 …

  18. Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands

  19. 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

  20. File System Hierarchy bin dev etc bin sbin etc / lib adm include spool tmp lib tmp var man usr local

  21. 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)

  22. 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

  23. 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

  24. Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands

  25. 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

  26. 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

  27. File permission modes • 3 permission modes: • read (r) • write (w) • execute (x) • 3 user categories: • user (u): the owner • group (g) • others (o)

  28. 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

  29. 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

  30. How to change the permissions (cont.) • Examples: • chmod 777 filename • chmod +gx filename

  31. Lesson Outline • Introduction • The file system • How to handle files and directories • Basic commands

  32. 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

  33. 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

  34. 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

  35. 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

  36. Text file analysis • pg file ... • more file ... • less file ...

  37. 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

  38. 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)

  39. 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

  40. Finding a file • find dir expression • search for files in a directory hierarchy • find /users -name core

  41. 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

  42. 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

  43. File Comparison • diff [-options] file1 file2 • compare files line by line

  44. time • time command • run programs and summarize system resource usage • Example: • time ls -la

  45. wc • wc file • Print the number of newlines, words, and bytes in files

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend