File Systems (ch 4) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng 1.
-
Upload
virginia-mccoy -
Category
Documents
-
view
229 -
download
1
Transcript of 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
2
Outline
• Filename and paths• Directory operations• Access permissions
3
Filenames and Paths
• Absolute path name
– ls /home/it244/it244– ls /home/it244/it244/
/home/it244/it244/hello
Path Filename
4
Filenames and Paths
• Absolute path name
5
Filenames and Paths
• Absolute path name– ~ represents “home directory”
– ls ~ =ls /home/your username– cd ~– pwd
– ls ~it244 =ls /home/it244
6
Filenames and Paths
• Relative path name
– cd /home/it244– ls it244
/home/it244/it244/hello
Path Filename
7
Filenames and Paths
• Relative path name– . : Current directory– .. : Parent directory
– ls –la– ls .– ls ..– cd ..– cd ../..
8
Filenames and Paths
• Relative path name
9
Filenames and Paths
• Standard directories (Pg 95~98)
10
Directory Operations
• Create a directory– mkdir book– ls -l– ls book– ls ./book– cd book– ls ../book
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)
12
Directory Operations
• Example– rm book/book1– rmdir book
• Delete directories by rm– mkdir book– rm book– rm –r book (cautious)
13
Directory Operations
• Example– mkdir book– cd book– mkdir novel– cd ..– rmdir book
– cd book/novel– rmdir .
14
Directory Operations
• Copy and move files to directories– cd ../..– cp hello book– ls book
– mv welcome linux book– ls– ls book
15
Directory Operations
• Copy and move files to directories– mv book newbook
– mv newbook book– ls
– mkdir newbook– mv book newbook
16
Directory Operations
• Copy and move files to directories– mv newbook/book book– cp book newbook ???
– cp –r book newbook– ls newbook
17
Access Permissions
• Three types of users– Owner– Group member– Others
• Three access permissions– Read– Write– Execute
18
Access Permissions
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
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
21
Access Permissions
• Change access permissions (chmod)– Numeric arguments
• chmod 644 book1• chmod 755 book1
22
Access Permissions
• Example– Read permission
• chmod a-r hello• cat hello• chmod a+r hello• cat hello
23
Access Permissions
• Example– Read permission
• chmod a-r book• ls book• ls book/book1• chmod a+r book
24
Access Permissions
• Example– Write permission
• chmod a-w hello• echo hi>hello
• rm hello• chmod a+w hello• rm hello
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 .
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?
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
28
Access Permissions
• Execute permission on files– Binary and script
– chmod a=x binary– ./binary
29
Access Permissions
• Execute permission on files– Binary and script
– chmod a=x script– ./script– chmod a=rx script
30
Access Permissions
• Execute permission on files– Binary ( x )– Script ( rx )
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
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
33
Links
• Pointer to a file or directory
34
Links
• Example– ls –l ~
– cd it244– pwd
35
Links
• Example– ls –l ~
/
it244username
usernameit244
home courses
36
Links
• Hard links and symbolic links– Hard links point to the actual data
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)
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
39
Links
• Hard links and symbolic links– Symbolic (soft) links are shortcuts
Hard link Symbolic link
40
Links
• Hard links and symbolic links– Symbolic (soft) links are shortcuts
– ln –s hello hello2– ls -l– ls –i hello hello1 hello2
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
42
Links
• Hard links and symbolic links– Remove links– rm hello1
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
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
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
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
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
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
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
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
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
52
Access Permissions
• Operations on book/book1– ls book
• book ( r )
– cd book• book ( x )
– echo “this is a book” > book/book2• book ( wx )
53
Access Permissions
• Operations on book/book1– ls book/book1
• book ( x )
– cat book/book1• book1 ( r ), book ( x )
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 )
55
Links
• Chained soft links– ln -s hello hello1– ln –s hello1 hello2
– rm hello1– cat hello2
56
Links
• Permissions on links– ln hello hello1– ls –l hello hello1 hello2
– chmod a-r hello1– chmod a+r hello2