File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

56
File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1

Transcript of File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

Page 1: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

1

File Systems (ch 4)

IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

Page 2: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

2

Outline

• Filename and paths• Directory operations• Access permissions

Page 3: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

3

Filenames and Paths

• Absolute path name

– ls /home/it244/it244– ls /home/it244/it244/

/home/it244/it244/hello

Path Filename

Page 4: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

4

Filenames and Paths

• Absolute path name

Page 5: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

5

Filenames and Paths

• Absolute path name– ~ represents “home directory”

– ls ~ =ls /home/your username– cd ~– pwd

– ls ~it244 =ls /home/it244

Page 6: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

6

Filenames and Paths

• Relative path name

– cd /home/it244– ls it244

/home/it244/it244/hello

Path Filename

Page 7: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

7

Filenames and Paths

• Relative path name– . : Current directory– .. : Parent directory

– ls –la– ls .– ls ..– cd ..– cd ../..

Page 8: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

8

Filenames and Paths

• Relative path name

Page 9: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

9

Filenames and Paths

• Standard directories (Pg 95~98)

Page 10: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

10

Directory Operations

• Create a directory– mkdir book– ls -l– ls book– ls ./book– cd book– ls ../book

Page 11: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

11

Directory Operations

• Delete a directory (when it’s empty)– cd ..– rmdir book

• Example– mkdir book– cd book– echo “this is a book” > book1– cd ..– rmdir book (not empty)

Page 12: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

12

Directory Operations

• Example– rm book/book1– rmdir book

• Delete directories by rm– mkdir book– rm book– rm –r book (cautious)

Page 13: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

13

Directory Operations

• Example– mkdir book– cd book– mkdir novel– cd ..– rmdir book

– cd book/novel– rmdir .

Page 14: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

14

Directory Operations

• Copy and move files to directories– cd ../..– cp hello book– ls book

– mv welcome linux book– ls– ls book

Page 15: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

15

Directory Operations

• Copy and move files to directories– mv book newbook

– mv newbook book– ls

– mkdir newbook– mv book newbook

Page 16: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

16

Directory Operations

• Copy and move files to directories– mv newbook/book book– cp book newbook ???

– cp –r book newbook– ls newbook

Page 17: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

17

Access Permissions

• Three types of users– Owner– Group member– Others

• Three access permissions– Read– Write– Execute

Page 18: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

18

Access Permissions

Page 19: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

19

Access Permissions

• Change access permissions (chmod)– Symbolic arguments

• a (all), u (owner), g (group), o (others)• r (read), w (write), x (execute)• + / -

• chmod a+w book1• chmod go-rw book1

Page 20: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

20

Access Permissions

• Change access permissions (chmod)– Numeric arguments

r w x 1

2

3

4

5

6

7

-rw-r--r--644

-rwxr-xr-x755

Page 21: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

21

Access Permissions

• Change access permissions (chmod)– Numeric arguments

• chmod 644 book1• chmod 755 book1

Page 22: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

22

Access Permissions

• Example– Read permission

• chmod a-r hello• cat hello• chmod a+r hello• cat hello

Page 23: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

23

Access Permissions

• Example– Read permission

• chmod a-r book• ls book• ls book/book1• chmod a+r book

Page 24: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

24

Access Permissions

• Example– Write permission

• chmod a-w hello• echo hi>hello

• rm hello• chmod a+w hello• rm hello

Page 25: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

25

Access Permissions

• Example– Write permission

• cd book• chmod a-w .• chmod a+rw book1

• echo hi>book2 (create a file)• mv book1 book2 (rename a file)• rm book1 (delete a file)• chmod a+w .

Page 26: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

26

Access Permissions

• Example– Execute permission (directory)

• Determine if the files are searchable• chmod a-x book• ls book• ls book/book1

• cd book• chmod a+x book

Why?

Page 27: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

27

Access Permissions

• Execute permission on files– Binary and script

– cp /home/shengbo/it244/binary .– cp /home/shengbo/it244/script .

– ls –l (check the execute permission)– cat binary– cat script

Page 28: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

28

Access Permissions

• Execute permission on files– Binary and script

– chmod a=x binary– ./binary

Page 29: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

29

Access Permissions

• Execute permission on files– Binary and script

– chmod a=x script– ./script– chmod a=rx script

Page 30: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

30

Access Permissions

• Execute permission on files– Binary ( x )– Script ( rx )

Page 31: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

31

Access Control List

• ACL: fine-grained access control– getfacl and setfacl

• getfacl hello

• setfacl –m u:shengbo:rw- hello• getfacl hello

• setfacl –m u:shengbo:4 hello• getfacl hello

Page 32: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

32

Access Control List

• ACL: fine-grained access control– getfacl and setfacl

• setfacl –m u:shengbo:rw-,u:vijeth35:6 hello

• getfacl hello

• setfacl –x u:vijeth35 hello• getfacl hello

Page 33: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

33

Links

• Pointer to a file or directory

Page 34: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

34

Links

• Example– ls –l ~

– cd it244– pwd

Page 35: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

35

Links

• Example– ls –l ~

/

it244username

usernameit244

home courses

Page 36: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

36

Links

• Hard links and symbolic links– Hard links point to the actual data

Page 37: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

37

Links

• Hard links and symbolic links– Hard links point to the actual data

– ln hello hello1– ls -l– ls –i hello hello1 (inode number)

Page 38: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

38

Links

• Hard links and symbolic links– Hard links point to the actual data

– cat hello hello1– rm hello– cat hello1– ln VS. cp

– Hard links cannot point to directories

Page 39: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

39

Links

• Hard links and symbolic links– Symbolic (soft) links are shortcuts

Hard link Symbolic link

Page 40: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

40

Links

• Hard links and symbolic links– Symbolic (soft) links are shortcuts

– ln –s hello hello2– ls -l– ls –i hello hello1 hello2

Page 41: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

41

Links

• Hard links and symbolic links– Symbolic (soft) links are shortcuts

– cat hello hello1 hello2– rm hello– cat hello1– cat hello2– echo hi > hello– cat hello hello1 hello2

Page 42: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

42

Links

• Hard links and symbolic links– Remove links– rm hello1

Page 43: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

43

Summary

• More about file system and inode

Data blocks

inode

file1

File type

Size

Permissions

Block addr

Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

Inode table

Page 44: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

44

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

Data blocks

inode

file2Inode table

Page 45: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

45

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

Data blocks

inode

file2Inode table

Filename Inode number

file1 inum1

file2 inum3

Directory

Page 46: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

46

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

Data blocks

inode

file2Inode table

Filename Inode number

file1 inum1

file2 inum3

Directory

cp file1 file3

Page 47: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

47

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

inum4 iaddr4

Data blocks

inode

file3Inode table

Filename Inode number

file1 inum1

file2 inum3

file3 inum4

Directory

cp file1 file3

Page 48: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

48

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

Data blocks

inode

file2Inode table

Filename Inode number

file1 inum1

file2 inum3

Directory

ln file1 file3

Page 49: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

49

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

Data blocks

inode

file2Inode table

Filename Inode number

file1 inum1

file2 inum3

file3 inum1

Directory

ln file1 file3

Page 50: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

50

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

Data blocks

inode

file2Inode table

Filename Inode number

file1 inum1

file2 inum3

Directory

ln –s file1 file3

Page 51: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

51

Summary

• More about file system and inode

Data blocks

inode

file1Inode number

Inode addr

inum1 iaddr1

inum2 iaddr2

inum3 iaddr3

inum4 iaddr4

Data blocks“file1”

inode

file3Inode table

Filename Inode number

file1 inum1

file2 inum3

file3 inum4

Directory

ln –s file1 file3

inode inum4, iaddr4

Page 52: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

52

Access Permissions

• Operations on book/book1– ls book

• book ( r )

– cd book• book ( x )

– echo “this is a book” > book/book2• book ( wx )

Page 53: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

53

Access Permissions

• Operations on book/book1– ls book/book1

• book ( x )

– cat book/book1• book1 ( r ), book ( x )

Page 54: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

54

Access Permissions

• Operations on book/book1– rm book/book1

• book ( xw ), book1 ( w )

– cp book/book1 book/book2• book ( xw ), book1 ( r )

– mv book/book1 book/book3• book ( xw )

Page 55: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

55

Links

• Chained soft links– ln -s hello hello1– ln –s hello1 hello2

– rm hello1– cat hello2

Page 56: File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.

56

Links

• Permissions on links– ln hello hello1– ls –l hello hello1 hello2

– chmod a-r hello1– chmod a+r hello2