Advanced UNIX 240 491 Special Topics in Comp

  • Slides: 22
Download presentation
Advanced UNIX 240 -491 Special Topics in Comp. Eng. 1 Semester 2, 2000 -2001

Advanced UNIX 240 -491 Special Topics in Comp. Eng. 1 Semester 2, 2000 -2001 . 1 The File Structure (Ch. 4, Sobell( v Objectives – to supplement the “Introduction to UNIX” slides with extra information on files 240 -491 Adv. UNIX: File. Str/1 1

Overview. 1. 2 Access Permissions Links 240 -491 Adv. UNIX: File. Str/1 2

Overview. 1. 2 Access Permissions Links 240 -491 Adv. UNIX: File. Str/1 2

. 1 Access Permissions 1. 1 1. 2 1. 3 1. 4 Types of

. 1 Access Permissions 1. 1 1. 2 1. 3 1. 4 Types of Users and Access More File Information Access Permission Characters Changing Permissions 240 -491 Adv. UNIX: File. Str/1 3

. 1. 1 Types of User and Access v Types of user: – creator

. 1. 1 Types of User and Access v Types of user: – creator / owner – group – others u g o v Types of access: – read – write – execute 240 -491 Adv. UNIX: File. Str/1 r w x 4

. 1. 2 More File Information $ls -l. F -rwxr-xr-x drwxr-xr-x -rw-r--r-- v 1

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

. 1. 3 Access Permission Chars v First 3 chars: – refer to creator/owner

. 1. 3 Access Permission Chars v First 3 chars: – refer to creator/owner (u( v Middle 3 chars: – refer to group (g( v Last 3 chars: – refer to everyone else (o( 240 -491 Adv. UNIX: File. Str/1 6

v The 3 characters for u, g, and o have the same format: –

v 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 240 -491 Adv. UNIX: File. Str/1 7

. 1. 4 Changing Permissions chmod who+what file chmod who-what file who: what: //

. 1. 4 Changing Permissions chmod who+what file chmod who-what file who: what: // add a permission // remove u, g, o, a (all) r, w, x and combinations v Examples: chmod u+x foo-p chmod a+rw letter. txt chmod o-rx check_spell 240 -491 Adv. UNIX: File. Str/1 8

$chmod a+rw letter. txt $ ls -lg letter. txt -rw-rw-rw- 1 ad staff 3355

$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 240 -491 Adv. UNIX: File. Str/1 852 May 5 14: 03 check_spell 9

Warning v Your files and directories are automatically protected correctly. v Don’t change their

Warning v Your files and directories are automatically protected correctly. v Don’t change their permissions unless you really know what you are doing. 240 -491 Adv. UNIX: File. Str/1 10

Directory Access v Let everyone ls, add/remove and cd to my info directory: $chmod

Directory Access v Let everyone ls, add/remove and cd to my info directory: $chmod a+rwx /home/ad/info v Check permissions: $ls -ld. F /home/ad/info drwxrwxrwx 3 ad staff 112 Apr 15 11: 05 /home/ad/info 240 -491 Adv. UNIX: File. Str/1 11

. 2 Links 2. 1 2. 2 2. 3 2. 4 2. 5 240

. 2 Links 2. 1 2. 2 2. 3 2. 4 2. 5 240 -491 Adv. UNIX: File. Str/1 What is a Link? Creating a Link Seeing Links Removing a Link Symbolic Links 12

. 2. 1 What is a Link? v A link is a pointer to

. 2. 1 What is a Link? v A link is a pointer to a file. v Useful for sharing files: – a file can be shared by giving each person their own link (pointer) to it. 240 -491 Adv. UNIX: File. Str/1 13

. 2. 2 Creating a Link ln existing-file new-pointer v Jenny types: ln draft

. 2. 2 Creating a Link ln existing-file new-pointer v Jenny types: ln draft /home/ad/letter / /home/jenny/draft and /home/ad/letter memo 240 -491 Adv. UNIX: File. Str/1 home ad jenny planning 14

v Changes to a file affects every link: $cat file_a This is file A.

v 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 This $ cat This 240 -491 Adv. UNIX: File. Str/1 file_b is file B after the change. file_a is file B after the change. 15

. 2. 3 Seeing Links v Compare status information: $ls -l file_a file_b file_c

. 2. 3 Seeing Links v Compare status information: $ls -l file_a file_b file_c file_d -rw-r--r--rw-r--r-- 2 2 1 1 ad ad 33 33 16 33 May May 24 24 10: 52 10: 55 10: 57 file_a file_b file_c file_d v Look at inode number: $ls -i file_a file_b file_c file_d 3534 file_a 5800 file_c 240 -491 Adv. UNIX: File. Str/1 3534 file_b 7328 file_d 16

v Directories may appear to have many links: drwxr-xr-x 23 ad users 1024 Jan

v Directories may appear to have many links: drwxr-xr-x 23 ad users 1024 Jan 12 2000 BLP/ v This is because subdirectories (e. g. directories inside BLP/) have a link back to their parent. 240 -491 Adv. UNIX: File. Str/1 17

. 2. 4 Removing a Link v Deleting a link does not remove the

. 2. 4 Removing a Link v Deleting a link does not remove the file. v Only when the file and every link is gone will the file be removed. 240 -491 Adv. UNIX: File. Str/1 18

. 2. 5 Symbolic Links v The links described so far are often called

. 2. 5 Symbolic Links v 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 v A symbolic link is an indirect pointer to a file – it stores the pathname of the pointed-to file – it can link across filesystems 240 -491 Adv. UNIX: File. Str/1 19

v Jenny types: ln -s shared /home/ad/project / /home/jenny/shared and /home/ad/project separate filesystem 240

v Jenny types: ln -s shared /home/ad/project / /home/jenny/shared and /home/ad/project separate filesystem 240 -491 Adv. UNIX: File. Str/1 home ad memo jenny planning 20

v Symbolic links are listed differently: $ln -s pics /home/ad/images $ ls -l. F

v Symbolic links are listed differently: $ln -s pics /home/ad/images $ ls -l. F 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 240 -491 Adv. UNIX: File. Str/1 21

v Symbolic links can confuse: $ln -s /home/ad/grades /tmp/grades-old $ cd /tmp/grades-old $ pwd

v Symbolic links can confuse: $ln -s /home/ad/grades /tmp/grades-old $ cd /tmp/grades-old $ pwd /home/ad/grades $ echo $cwd /tmp/grades-old (C Shell only) $ cd. . $ echo $cwd /home/ad 240 -491 Adv. UNIX: File. Str/1 22