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

240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

Embed Size (px)

Citation preview

Page 1: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 1

Advanced UNIXAdvanced UNIX

ObjectivesObjectives– to supplement the “Introduction to UNIX” to supplement the “Introduction to UNIX”

slides with extra information on filesslides with extra information on files

240-491 Special Topics in Comp. Eng. 1Semester 2, 2000-2001

1. The File Structure(Ch.4, Sobell)

Page 2: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 2

OverviewOverview

1.1. Access PermissionsAccess Permissions

2.2. LinksLinks

Page 3: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 3

1. Access Permissions1. Access Permissions

1.11.1 Types of Users and AccessTypes of Users and Access

1.21.2 More File InformationMore File Information

1.31.3 Access Permission CharactersAccess Permission Characters

1.41.4 Changing PermissionsChanging Permissions

Page 4: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 4

1.1. Types of User and Access1.1. Types of User and Access

Types of user:Types of user:– creator / ownercreator / owner uu– groupgroup gg– othersothers oo

Types of access:Types of access:– readread rr– writewrite ww– executeexecute xx

Page 5: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 5

1.2. More File Information1.2. More File Information

$ ls -lF$ ls -lF-rwxr-xr-x 1 ad users 443275 Sep 26 15:02 BLP.gz*-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-rwxr-xr-x 2 ad users 852 May 5 14:03 check_spelldrwxr-xr-x 2 ad users 1024 Sep 26 16:04 curses/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-rw-r--r-- 1 ad users 3355 May 2 10.52 letter.txt

Meaning (left to right):Meaning (left to right):– file type (first char)file type (first char)

– file access permission (9 chars)file access permission (9 chars)

– number of linksnumber of links

– owner’s nameowner’s name

– group namegroup name

- byte size of file- creation time/ last modified- name, with / or * ending

Page 6: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 6

1.3. Access Permission Chars1.3. Access Permission Chars

First 3 chars:First 3 chars:– refer to creator/owner (u)refer to creator/owner (u)

Middle 3 chars:Middle 3 chars:– refer to group (g)refer to group (g)

Last 3 chars:Last 3 chars:– refer to everyone else (o)refer to everyone else (o)

Page 7: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 7

The 3 characters for u, g, and o have the The 3 characters for u, g, and o have the same format:same format:– First characterFirst character indicates whether the file can be indicates whether the file can be readread ( (rr). ).

For a directory, this means you can do a For a directory, this means you can do a lsls..

– Second characterSecond character indicates whether the file can be indicates whether the file can be writtenwritten to ( to (ww). ). For a directory, you can add/remove files.For a directory, you can add/remove files.

– Third characterThird character indicates whether the file can be indicates whether the file can be executedexecuted ( (xx). ). For a directory, you can do a For a directory, you can do a cdcd.. A bit hard to

remember

Page 8: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 8

1.4. Changing Permissions1.4. Changing Permissions

chmod whochmod who++what filewhat file // add a permission // add a permissionchmod whochmod who--what filewhat file // remove // remove

who:who: u, g, o, a (all)u, g, o, a (all)what:what: r, w, xr, w, x

and combinationsand combinations

Examples:Examples:chmod u+x foo-pchmod u+x foo-p

chmod a+rw letter.txtchmod a+rw letter.txt

chmod o-rx check_spellchmod o-rx check_spell

Page 9: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 9

$ chmod $ chmod a+rw a+rw letter.txtletter.txt$ ls -lg letter.txt$ ls -lg letter.txt

-rw-rw-rw- -rw-rw-rw- 1 ad staff 3355 May 2 10:52 letter.txt1 ad staff 3355 May 2 10:52 letter.txt

$ chmod $ chmod o-rxo-rx check_spell check_spell$ ls -lg check_spell$ ls -lg check_spell

-rwxr-x--- -rwxr-x--- 2 ad staff 852 May 5 14:03 check_spell2 ad staff 852 May 5 14:03 check_spell

Page 10: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 10

WarningWarning

Your files and directories are automatically Your files and directories are automatically protected correctly.protected correctly.

Don’t change their permissions unless you Don’t change their permissions unless you really know what you are doing.really know what you are doing.

Page 11: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 11

Directory AccessDirectory Access

Let everyone Let everyone lsls, add/remove and , add/remove and cdcd to my to my infoinfo

directory:directory:$ chmod a+rwx /home/ad/info$ chmod a+rwx /home/ad/info

Check permissions:Check permissions:$ ls -l$ ls -lddF /home/ad/infoF /home/ad/info

drwxrwxrwx 3 ad staff 112 Apr 15 11:05 drwxrwxrwx 3 ad staff 112 Apr 15 11:05

/home/ad/info/home/ad/info

Page 12: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 12

2. Links2. Links

2.12.1 What is a Link?What is a Link?

2.22.2 Creating a LinkCreating a Link

2.32.3 Seeing LinksSeeing Links

2.42.4 Removing a LinkRemoving a Link

2.52.5 Symbolic LinksSymbolic Links

Page 13: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 13

2.1. What is a Link?2.1. What is a Link?

A link is a pointer to a file.A link is a pointer to a file.

Useful for sharing files:Useful for sharing files:– a file can be shared by giving each person their a file can be shared by giving each person their

own link (pointer) to it.own link (pointer) to it.

Page 14: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 14

2.2. Creating a Link2.2. Creating a Link

ln existing-file new-pointerln existing-file new-pointer

Jenny types:Jenny types:ln draft /home/ad/letterln draft /home/ad/letter

/

home

ad jenny

memo planning

/home/jenny/draftand/home/ad/letter

Page 15: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 15

Changes to a file affects every link:Changes to a file affects every link:

$ $ cat file_acat file_aThis is file A.This is file A.$ $ ln file_a file_bln file_a file_b$ $ cat file_bcat file_bThis is file A.This is file A.

$ $ vi file_bvi file_b : :

$ $ cat file_bcat file_bThis is file B after the change.This is file B after the change.$ $ cat file_acat file_aThis is file B after the change.This is file B after the change.

Page 16: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 16

2.3. Seeing Links2.3. Seeing Links

Compare status information:Compare status information:$ ls -l file_a file_b file_c file_d$ 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_a-rw-r--r-- 2 ad 33 May 24 10:52 file_b-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 16 May 24 10:55 file_c-rw-r--r-- 1 ad 33 May 24 10:57 file_d-rw-r--r-- 1 ad 33 May 24 10:57 file_d

Look at inode number:Look at inode number:$ ls -i file_a file_b file_c file_d$ ls -i file_a file_b file_c file_d

35343534 file_a file_a 35343534 file_b file_b 5800 file_c 7328 file_d5800 file_c 7328 file_d

Page 17: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 17

Directories may appear to have many links:Directories may appear to have many links:drwxr-xr-x drwxr-xr-x 2323 ad users 1024 Jan 12 2000 BLP/ ad users 1024 Jan 12 2000 BLP/

This is because subdirectories (e.g. This is because subdirectories (e.g. directories inside directories inside BLP/BLP/) have a link back to ) have a link back to their parent.their parent.

Page 18: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 18

2.4. Removing a Link2.4. Removing a Link

Deleting a link does not remove the file.Deleting a link does not remove the file.

Only when the file Only when the file andand every link is gone every link is gone will the file be removed.will the file be removed.

Page 19: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 19

2.5. Symbolic Links2.5. Symbolic Links

The links described so far are often called The links described so far are often called hard linkshard links– a hard link is a pointer to a file which must be on a hard link is a pointer to a file which must be on

the the samesame filesystem filesystem

A A symbolic linksymbolic link is an is an indirect pointerindirect pointer to a file to a file– it stores the pathname of the pointed-to fileit stores the pathname of the pointed-to file– it can link across filesystemsit can link across filesystems

Page 20: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 20

Jenny types:Jenny types:ln ln -s-s shared /home/ad/project shared /home/ad/project

/

home

ad jenny

memo planning

/home/jenny/sharedand/home/ad/project

separatefilesystem

Page 21: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 21

Symbolic links are listed differently:Symbolic links are listed differently:

$ ln -s pics /home/ad/images$ ln -s pics /home/ad/images

$ ls -lF pics /home/ad/images$ ls -lF pics /home/ad/images

drw-r--r-- 1 ad staff 981 May 24 10:55 picsdrw-r--r-- 1 ad staff 981 May 24 10:55 picslrwxrwxrxw 1 ad staff 4 May 24 10:57 lrwxrwxrxw 1 ad staff 4 May 24 10:57

/home/ad/images --> pics/home/ad/images --> pics

Page 22: 240-491 Adv. UNIX: FileStr/11 Advanced UNIX v Objectives –to supplement the “Introduction to UNIX” slides with extra information on files 240-491 Special

240-491 Adv. UNIX: FileStr/1 22

Symbolic links can confuse:Symbolic links can confuse:

$ ln -s /home/ad/grades /tmp/grades-old$ ln -s /home/ad/grades /tmp/grades-old$ cd /tmp/grades-old$ cd /tmp/grades-old$ pwd$ pwd/home/ad/grades/home/ad/grades

$ echo $cwd$ echo $cwd (C Shell only)(C Shell only)/tmp/grades-old/tmp/grades-old

$ cd ..$ cd ..$ echo $cwd$ echo $cwd/home/ad/home/ad