advanced unix
play

Advanced UNIX CIS 218 Advanced UNIX 1 . The File Structure (Ch. 4 , - PowerPoint PPT Presentation

Advanced UNIX CIS 218 Advanced UNIX 1 . The File Structure (Ch. 4 , Sobell) Objectives to supplement the Introduction to UNIX slides with extra information on files 1 CIS 218 Advanced UNIX Overview 1 . Access Permissions 2 . Links 2


  1. Advanced UNIX CIS 218 Advanced UNIX 1 . The File Structure (Ch. 4 , Sobell)  Objectives – to supplement the “Introduction to UNIX” slides with extra information on files 1 CIS 218 Advanced UNIX

  2. Overview 1 . Access Permissions 2 . Links 2 CIS 218 Advanced UNIX

  3. 1 . Access Permissions 1 . 1 Types of Users and Access 1 . 2 More File Information 1 . 3 Access Permission Characters 1 . 4 Changing Permissions 3 CIS 218 Advanced UNIX

  4. 1 . 1 . Types of User and Access  Types of user: – creator / owner u – group g – others o  Types of access: – read r – write w – execute x 4 CIS 218 Advanced UNIX

  5. 1 . 2 . More File Information $ ls -lF -rwxr-xr-x 1 ad users 443275 Sep 26 15 : 02 BLP.gz* -rwxr-xr-x 2 ad users 852 May 5 14 : 03 check_spell drwxr-xr-x 2 ad users 1024 Sep 26 16 : 04 curses/ -rw-r--r-- 1 ad users 3355 May 2 10 . 52 letter.txt  Meaning (left to right): – file type (first char) - byte size of file - creation time/ – file access permission ( 9 chars) last modified – number of links - name, with / or * – owner’s name ending – group name 5 CIS 218 Advanced UNIX

  6. 1 . 3 . Access Permission Chars  First 3 chars: – refer to creator/owner (u)  Middle 3 chars: – refer to group (g)  Last 3 chars: – refer to everyone else (o) 6 CIS 218 Advanced UNIX

  7.  The 3 characters for u, g, and o have the same format: – First character indicates whether the file can be read ( r). For a directory, this means you can do a ls . – Second character indicates whether the file can be written to (w). For a directory, you can add/remove files. – Third character indicates whether the file can be executed ( x). For a directory, you can do a cd . A bit hard to remember 7 CIS 218 Advanced UNIX

  8. 1 . 4 . Changing Permissions chmod who + what file // add a permission chmod who - what file // remove who: u, g, o, a (all) what: r, w, x and combinations  Examples: chmod u+x foo-p chmod a+rw letter.txt chmod o-rx check_spell 8 CIS 218 Advanced UNIX

  9. $ chmod a+rw letter.txt $ ls -lg letter.txt -rw-rw-rw- 1 ad staff 3355 May 2 10 : 52 letter.txt $ chmod o-rx check_spell $ ls -lg check_spell -rwxr-x--- 2 ad staff 852 May 5 14 : 03 check_spell 9 CIS 218 Advanced UNIX

  10. Warning  Your files and directories are automatically protected correctly.  Don’t change their permissions unless you really know what you are doing. 10 CIS 218 Advanced UNIX

  11. Directory Access  Let everyone ls , add/remove and cd to my info directory: $ chmod a+rwx /home/ad/info  Check permissions: $ ls -l d F /home/ad/info drwxrwxrwx 3 ad staff 112 Apr 15 11: 05 /home/ad/info 11 CIS 218 Advanced UNIX

  12. 2 . Links 2 . 1 What is a Link? 2 . 2 Creating a Link 2 . 3 Seeing Links 2 . 4 Removing a Link 2 . 5 Symbolic Links 12 CIS 218 Advanced UNIX

  13. 2 . 1 . What is a Link?  A link is a pointer to a file.  Useful for sharing files: – a file can be shared by giving each person their own link (pointer) to it. 13 CIS 218 Advanced UNIX

  14. 2 . 2 . Creating a Link ln existing-file new-pointer  Jenny types: ln draft /home/ad/letter / /home/jenny/draft home and /home/ad/letter ad jenny memo planning 14 CIS 218 Advanced UNIX

  15.  Changes to a file affects every link: $ cat file_a This is file A. $ ln file_a file_b $ cat file_b This is file A. $ vi file_b : $ cat file_b This is file B after the change. $ cat file_a This is file B after the change. 15 CIS 218 Advanced UNIX

  16. 2 . 3 . Seeing Links  Compare status information: $ ls -l file_a file_b file_c file_d -rw-r--r-- 2 ad 33 May 24 10 : 52 file_a -rw-r--r-- 2 ad 33 May 24 10 : 52 file_b -rw-r--r-- 1 ad 16 May 24 10 : 55 file_c -rw-r--r-- 1 ad 33 May 24 10 : 57 file_d  Look at inode number: $ ls -i file_a file_b file_c file_d 3534 file_a 3534 file_b 5800 file_c 7328 file_d 16 CIS 218 Advanced UNIX

  17.  Directories may appear to have many links: drwxr-xr-x 23 ad users 1024 Jan 12 2000 BLP/  This is because subdirectories (e.g. directories inside BLP/ ) have a link back to their parent. 17 CIS 218 Advanced UNIX

  18. 2 . 4 . Removing a Link  Deleting a link does not remove the file.  Only when the file and every link is gone will the file be removed. 18 CIS 218 Advanced UNIX

  19. 2 . 5 . Symbolic Links  The links described so far are often called hard links – a hard link is a pointer to a file which must be on the same filesystem  A symbolic link is an indirect pointer to a file – it stores the pathname of the pointed-to file – it can link across filesystems 19 CIS 218 Advanced UNIX

  20.  Jenny types: ln -s shared /home/ad/project / /home/jenny/shared home and /home/ad/project ad jenny separate memo planning filesystem 20 CIS 218 Advanced UNIX

  21.  Symbolic links are listed differently: $ ln -s pics /home/ad/images $ ls -lF pics /home/ad/images drw-r--r-- 1 ad staff 981 May 24 10 : 55 pics lrwxrwxrxw 1 ad staff 4 May 24 10: 57 /home/ad/images --> pics 21 CIS 218 Advanced UNIX

  22.  Symbolic links can confuse: $ ln -s /home/ad/grades /tmp/grades-old $ cd /tmp/grades-old $ pwd /home/ad/grades $ echo $cwd (C Shell only) /tmp/grades-old $ cd .. $ echo $cwd /home/ad 22 CIS 218 Advanced UNIX

Recommend


More recommend