Download presentation
Presentation is loading. Please wait.
1
UNIX file systems Learning Objectives: 1. To understand the basics of file systems 2. To understand the hierarchical structure in Unix file system 3. To learn the Unix commands for files / directories’ manipulations 4. To learn the security & access permission for files / directories in Unix System
2
COMP111 Lecture 3 / Slide 2 Unix File System Table of contents Files systems Unix file systems Home & working directories Directory shorthand Special directories Naming files Pathnames Directory commands Security & access permissions Directory permissions Changing permissions Permissions – example
3
COMP111 Lecture 3 / Slide 3 File Systems What is a file system? A means of organizing information on the computer. A file system is a logical view, not necessarily a physical view. What does the file system provide: Ways to create, move, and remove files Ways to order files Security Examples of file systems: DOS, Macintosh, CD-ROM, UNIX, NFS (networked file system)
4
COMP111 Lecture 3 / Slide 4 Hierarchical Organization Single root of tree is at top denoted by ‘/’ Kinds of files: Directory files (the branches in the tree) Regular files (leaves in the tree) UNIX File Systems / binlibhomes horner.mailrctop10111 jbond...
5
COMP111 Lecture 3 / Slide 5 Home and Working Directories Home directory The directory you are in when you first login in This is your space; you control security Place to put your personalized.startup files Your working directory after typing cd with no arguments Working directory Can access files in your working directory by simply typing the filename To access files in other directories, must use a pathname pwd command prints the working directory cd command changes the working directory
6
COMP111 Lecture 3 / Slide 6 Directory Shorthands “.” is the directory itself “..” is the parent directory In most shells “~” means your home directory) ~user means user’s home directory, so: $ more ~jbond/.plan looks at the file.plan in /home/jbond, which is jbond ’s home directory.
7
COMP111 Lecture 3 / Slide 7 Special Directories “ / ” (pronounced “slash” and also called “the “root”) is the ancestor of all files in the file system /bin and /usr/bin contain UNIX utilities (e.g., cat ) /dev contains special files which describe “devices” such as terminals and printers /etc has administrative programs like password files /tmp is for temporary files; periodically deleted Every directory has at least two entries: “.” is the directory itself, and “..” is the directory’s parent
8
COMP111 Lecture 3 / Slide 8 Naming Files Files in the same directory can’t have the same name Case sensitive: secret and Secret are different Files are sometimes named with an extension (e.g., bond.cpp, 007.html ) to show the file’s content. You cannot create a file named “.” or “..” “Invisible” files and directories (those that don’t appear using ls ) have a period as the first character (e.g.,.plan,.xinitrc ). Some programs use invisible files to store information.
9
COMP111 Lecture 3 / Slide 9 Pathnames Simple filenames Can only be used if files are in working directory Relative pathname A string of directory references, beginning with the working directory. Examples:./secret1../007/names top10/LG7soBad Absolute pathname A pathname beginning at the root. e.g.,: /homes/jbond/.plan /etc/passwd
10
COMP111 Lecture 3 / Slide 10 Directory Commands (1) mkdir makes a new directory (if you have permission to do so). With a simple pathname, mkdir makes a new directory in your working directory. $ pwd /homes/jbond/111 $ ls -l total 6 -rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3 -rw-r--r-- 1 jbond cs 64 Feb 4 15:00 names drwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/ $ mkdir newdir $ ls -l total 8 -rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3 -rw-r--r-- 1 jbond cs 64 Feb 4 15:00 names drwxr-xr-x 2 jbond cs 512 Feb 4 15:26 newdir/ drwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/
11
COMP111 Lecture 3 / Slide 11 Directory Commands (2) rmdir deletes a directory (if you have permission). $ rmdir newdir $ ls -l total 6 -rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3 -rw-r--r-- 1 jbond cs 64 Feb 4 15:00 names drwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/ $ rmdir /usr rmdir: directory "/usr": Search or write permission needed
12
COMP111 Lecture 3 / Slide 12 Directory Commands (3) mv can be used to move a file to another directory. $ ls letter3names newdir/secret/ $ mv letter3 secret $ ls namessecret/ $ ls secret letter3 mv can be used to move a directory into a directory. $ ls namesnewdir/secret/ $ mv newdir secret $ ls namessecret/ $ ls secret letter3newdir/
13
COMP111 Lecture 3 / Slide 13 Directory Commands (4) You can also move several files at once using mv $ ls letter1letter2namessecret/ $ mv letter* secret $ ls namessecret/ $ ls secret letter1letter2
14
COMP111 Lecture 3 / Slide 14 Directory Commands (5) You can list all files in a directory tree $ ls -R add |more if necessary.: namessecret/./secret: letter1letter2 (try yourself: ls -lR, ls -ldR) You can find files in a directory tree $ find. -name ‘letter*’ -print./secret/letter1./secret/letter2
15
COMP111 Lecture 3 / Slide 15 Directory Commands (6) You can copy a directory tree to another tree $ cp -R secret secret2 You can delete a whole directory tree (Be careful!) $ rm -R secret2 You may want to use the -i option for prompting: $ rm -Ri secret2 rm: examine files in directory secret2 (yes/no)? y rm: remove secret2/letter1 (yes/no)? y rm: remove secret2/letter2 (yes/no)? y rm: remove secret2: (yes/no)? y
16
COMP111 Lecture 3 / Slide 16 Security and Access Permissions (1) There are three types of users: The owner of the file (user) The group of the file (group) Anyone else (other) There are three types of permission (independent of each other): Read permission Write permission Execute permission
17
COMP111 Lecture 3 / Slide 17 Use ls -l to see file permissions -rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3 There are four sets of items in the permissions: -rw-r--r-- The type is: “ - ” regular files, “ d ” directories, “ l ” symbolic links. The next nine characters indicate if the file is readable, writable, or executable for the file owner, the file group, or other users, respectively. Security and Access Permissions (2) PermissionsUser Group Byte size Last modification Name #links usergroupother type
18
COMP111 Lecture 3 / Slide 18 Security and Access Permissions (3) Examples: $ ls -l total 34 -r-xr-xr-x 1 jbond cs 9388 Feb 4 16:31 cat* -rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter1 -rw------- 1 jbond cs 64 Feb 4 15:00 names drwxr-xr-x 2 jbond cs 512 Feb 4 15:41 newdir/ drwxr-xr-x 2 jbond cs 512 Feb 4 16:38 secret/ d--------- 2 jbond cs 512 Feb 4 16:39 secret1/ dr--r--r-- 2 jbond cs 512 Feb 4 16:39 secret2/ d--x--x--x 2 jbond cs 512 Feb 4 16:38 secret3/
19
COMP111 Lecture 3 / Slide 19 Directory Permissions (1) Can use ls -ld to lists a directory’s information (instead of its contents): $ ls -l secret total 4 -rw-r--r-- 1 jbond cs 154 Feb 4 16:38 letter1 -rw-r--r-- 1 jbond cs 34 Feb 4 15:00 letter4 $ ls -ld secret drwxr-xr-x 2 jbond cs 512 Feb 4 16:38 secret/ $ ls -ld secret* drwxr-xr-x 2 jbond cs 512 Feb 4 16:38 secret/ d--------- 2 jbond cs 512 Feb 4 16:39 secret1/ dr--r--r-- 2 jbond cs 512 Feb 4 16:39 secret2/ d--x--x--x 2 jbond cs 512 Feb 4 16:38 secret3/
20
COMP111 Lecture 3 / Slide 20 Directory Permissions (2) PermissionFor a FileFor a Directory r (read)Contents can be viewed or printed. Contents can be read, but not searched. Normally r and x are used together. w (write)Contents can be changed or deleted. Entries can be added or removed. x (execute)File can be used as a program. Directory can be searched.
21
COMP111 Lecture 3 / Slide 21 Directory Permissions (3) $ ls -l secret* secret: total 2 -rw-r--r-- 1 jbond cs 154 Feb 4 16:38 letter1 secret1: secret1: Permission denied total 2 secret2: secret2/letter1: Permission denied total 0 secret3: secret3: Permission denied total 0 $ ls -l secret*/letter1 -rw-r--r-- 1 jbond cs 154 Feb 4 16:38 secret/letter1 -rw-r--r-- 1 jbond cs 154 Feb 4 16:39 secret3/letter1 drwxr-xr-x secret/ d--------- secret1/ dr--r--r-- secret2/ d--x--x--x secret3/
22
COMP111 Lecture 3 / Slide 22 Changing Permissions (1) The chmod command is used to modify permissions. chmod can only be used by the owner of a file/dir (or the administrator root). The arguments are: chmod [ugoa] [+-=] [rwxdd] [file/dir] In other words: Optionally, one of the characters: u (user/owner), g (group), o (other), or a (all). Optionally, one of the characters: + (add permission), - (remove permission), or = (set permission). Any combination of the characters r (read), w (write), or x (execute).
23
COMP111 Lecture 3 / Slide 23 Changing Permissions (2) Another way to change permission is to use numbers representing the permissions. The arguments are: chmod n u n g n o [file/dir] n u - user’s permission code n g - group’s permission code n o - other’s permission code -rwxrwxrwx Code table (3 bits) --- 0 r-- 4 --x 1 r-x5 -w- 2 rw-6 -wx 3 rwx7
24
COMP111 Lecture 3 / Slide 24 Permission Example To let everybody read or write the file letter1 $ chmod a+rw letter1 (chmod 666 letter1) $ ls -l letter1 -rw-rw-rw- 1 jbond cs 154 Feb 4 15:00 letter1 To allow user to execute file letter1 $ chmod u+x letter1(chmod 766 letter1) $ ls -l letter1 -rwxrw-rw- 1 jbond cs 154 Feb 4 15:00 letter1* To not let “other” to read or write file letter1 $ chmod o-rw letter1(chmod 760 letter1) $ ls -l letter1 -rwxrw---- 1 jbond cs 154 Feb 4 15:00 letter1* To let “group” only read the file letter1 $ chmod g=r letter1(chmod 740 letter1) $ ls -l letter1 -rwxr----- 1 jbond cs 154 Feb 4 15:00 letter1*
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.