unix file systems learning objectives: 1. to understand the basics of file systems 2. to understand...

24
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

Post on 19-Dec-2015

222 views

Category:

Documents


2 download

TRANSCRIPT

Page 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

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

Page 2: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 22

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

Page 3: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 33

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)

Page 4: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 44

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

/

bin libhomes

horner

.mailrc top10111

jbond

. . .

. . .

. . .

Page 5: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 55

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

Page 6: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 66

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.

Page 7: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 77

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

Page 8: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 88

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.

Page 9: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 99

Pathnames Simple filenames

Can only be used if files are in

working directory

Relative pathnameA string of directory references, beginning with the

working directory. Examples:./secret1../007/namestop10/LG7soBad

Absolute pathnameA pathname beginning at the root. e.g.,:

/homes/jbond/.plan/etc/passwd

Page 10: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1010

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 -ltotal 6-rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3-rw-r--r-- 1 jbond cs 64 Feb 4 15:00 namesdrwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/$ mkdir newdir$ ls -ltotal 8-rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3-rw-r--r-- 1 jbond cs 64 Feb 4 15:00 namesdrwxr-xr-x 2 jbond cs 512 Feb 4 15:26 newdir/drwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/

Page 11: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1111

Directory Commands (2)

rmdir deletes a directory

(if you have permission). $ rmdir newdir$ ls -ltotal 6-rw-r--r-- 1 jbond cs 154 Feb 4 15:00 letter3-rw-r--r-- 1 jbond cs 64 Feb 4 15:00 namesdrwxr-xr-x 2 jbond cs 512 Feb 4 15:00 secret/

$ rmdir /usrrmdir: directory "/usr": Search or write permission needed

Page 12: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1212

Directory Commands (3)

mv can be used to move a file to another directory. $ lsletter3 names newdir/ secret/$ mv letter3 secret$ lsnames secret/$ ls secretletter3

mv can be used to move a directory into a directory. $ lsnames newdir/ secret/$ mv newdir secret$ lsnames secret/$ ls secretletter3 newdir/

Page 13: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1313

Directory Commands (4)

You can also move several files at once using mv $ lsletter1 letter2 names secret/$ mv letter* secret$ lsnames secret/$ ls secretletter1 letter2

Page 14: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1414

Directory Commands (5)

You can list all files in a directory tree$ ls -R add |more if necessary.:names secret/

./secret:letter1 letter2

(try yourself: ls -lR, ls -ldR)

You can find files in a directory tree$ find . -name ‘letter*’ -print./secret/letter1./secret/letter2

Page 15: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1515

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 secret2rm: examine files in directory secret2 (yes/no)? yrm: remove secret2/letter1 (yes/no)? yrm: remove secret2/letter2 (yes/no)? yrm: remove secret2: (yes/no)? y

Page 16: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1616

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

Page 17: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1717

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)

Permissions User

Group Byte size

Last modification

Name#links

user group othertype

Page 18: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1818

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/

Page 19: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 1919

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/

Page 20: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 2020

Directory Permissions (2)

Permission For a File For 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.

Page 21: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 2121

Directory Permissions (3)

$ ls -l secret*secret:total 2-rw-r--r-- 1 jbond cs 154 Feb 4 16:38 letter1

secret1:secret1: Permission deniedtotal 2

secret2:secret2/letter1: Permission deniedtotal 0

secret3:secret3: Permission deniedtotal 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/

Page 22: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 2222

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).

Page 23: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 2323

Changing Permissions (2)

Another way to change permission is to use numbers representing the permissions. The arguments are:

chmod nungno [file/dir]

nu - user’s permission code

ng - group’s permission code

no - other’s permission code

-rwxrwxrwx

Code table (3 bits)

--- 0 r-- 4

--x 1 r-x 5

-w- 2 rw- 6

-wx 3 rwx 7

Page 24: 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

COMP111COMP111Lecture 3 / Slide Lecture 3 / Slide 2424

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*