Top Banner
The UNIX File System CS465
34

The UNIX File System

Jan 19, 2016

Download

Documents

frye

CS465. The UNIX File System. 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 - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The UNIX  File System

The UNIX

File System

CS465

Page 2: The UNIX  File System

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 3: The UNIX  File System

UNIX File System

• Heirarchical storage

– Basic storage unit is a FILE

• Unix File: a collection of data

– Just a sequence of bytes

– No record or block structure is required

Page 4: The UNIX  File System

Unix File Types

• Ordinary file (stores info)

• Directory (holds other files and directories)

– Directory file contains information about files

• Special file (represents physical devices like printers, terminals, etc)

• Pipe (temporary file for command linkage)

Page 5: The UNIX  File System

File and Directory Names

• Names are case sensitive

• Can use any character, however:

– Avoid using: / > , ! ( ) # & < > | @ $ ^ * ?

• Legal but hard to use with shells

• Length: Up to 14 characters guaranteed

• Names must be unique inside a directory

• Files beginning with “.” are “invisible”

Page 6: The UNIX  File System

The Unix File SystemThe Unix File System

/ is the “root” directory.In our example there are three directories

in root.

The “home” directory contains directories of all

users on a system.

Each user can create and administer his/her own directories,

subdirectories and files.

progs notes .login

jones smith username

home etc tmp

/

A rooted tree file structure (inverted tree)

Page 7: The UNIX  File System

Some Common DirectoriesSome Common Directories

/ root ancestor of all files in the file system

/bin binary executable files

/dev special device files

/etc administrative files

/home user home directories

/tmp temporary files

/usr special user files or home directories

Page 8: The UNIX  File System

Pathnames• Absolute Path Name

– Every file and directory in the file system can be identified by a “full path name” (route from root to file)/home/sue/email/f1

• Relative path name– Location is relative to working directory

. Working directory.. Parent directory

– If working directory is /home/sue:email/f1

fred

/

home

sue

docs email

f1 f2

Page 9: The UNIX  File System

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 (current) directory– Can access files in your working directory by simply typing the

filename (relative pathname)– To access files in other directories, must use the absolute

pathname pwd prints the working directory

cd changes the working directory

Page 10: The UNIX  File System

Directory ShorthandsDirectory abbreviations:

. the directory itself

.. the parent directory Every directory contains . and .. files

In most shells “~” means your home directory)~user means user’s home directory

Example: ~small000/.login

is file .login in /home/small000, which is my home directory.

Page 11: The UNIX  File System

Finding YourselfFinding Yourself

• The command pwd tells you where you are in the file hierarchy.

• It gives you the absolute path to your location.

$ pwd

/home/small000

Page 12: The UNIX  File System

Changing DirectoriesChanging Directories

cd change directory (home)

cd .. go to parent directory

cd / go to the root directory

cd ~ go to my home directory

cd ~user go to user’s home directory

cd /etc go to the etc directory from root

cd ../sub go to the sub directory in myparent directory

Page 13: The UNIX  File System

Creating and Removing Directories

• A new directory can be created with the mkdir command– Note command cannot be shortened to md

• A directory can be removed using the rmdir command– The directory must be empty (no files or

subdirectories)– Note command cannot be shortened to rd

Page 14: The UNIX  File System

Links

• Can have many links to the same file

• One directory contains the actual file, and the others contain a name only, which links to the actual file

• ln -command for creating links

$ ln filename linkname

Page 15: The UNIX  File System

Linksln creates a new link, not a new file. The new link and the original filename are equivalent pointers to the file.

Example:

$ ln names lnames

jones

lnames namesletter3

007

Golden Eye

Tomorrow Never Dies

FileContents

Page 16: The UNIX  File System

Creating Directories

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/home/jbond$ mkdir newdir$ ls –ltotal 3-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/

Page 17: The UNIX  File System

Deleting Directories

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

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

Page 18: The UNIX  File System

Moving Stuff

mv can move a directory into a directory

$ lsnames newdir/ secret/$ mv newdir secret$ lsnames secret/$ ls secretletter newdir/

Page 19: The UNIX  File System

Access Permissions

• Every user has:– A username– A numeric uid (user identification) – A default group association– Optional assocations with other groups

• Command:id view your uid and default group

and which groups you belong to

Page 20: The UNIX  File System

Access Permissions• Every file has:

– A single owner

– An association with a single group

– A set of access permissions associated with it

• For a File, permissions control what can be done to the file contents

• For a Directory, permissions control whether a file in that directory can be listed, searched, renamed or removed

Page 21: The UNIX  File System

Changing Your Group Association

• When you first log in, you're group is set to the default group specified in your /etc/passwd file.  

• To change groups, use the newgrp command$ newgrp admin

• Once you've changed to the new group, if you create a new file, it will be owned by the new group.

Page 22: The UNIX  File System

Access Permissions• First character shows the file type:

– directory (d)

– plain file (-)

– link (l) -rwxr-xr-x-rwxr-xr-x Rest specify three types of users:

- user owner- group- others

rwxrwxr-xr-xr-xr-x

who are allowed to: (r) read (w) write (x) execute

Page 23: The UNIX  File System

Permission Settings

Permission For a File For a Directory

r (read) Contents can be viewed or printed.

Contents can be listed, but not searched. Normally r and x are used together.

w (write) Contents can be changed or deleted.

File entries can be added or removed.

x (execute) File can be run as a program.

Directory can be searched and you can cd to it.

Page 24: The UNIX  File System

Permission SettingsPermission Settings• Permission settings use octal numbers.

– r = 100 = 4

– w = 010 = 2

– x = 001 = 1

– None = 000 = 0

• These numbers are additive.

– rwx = 7 (4 + 2 + 1) = 111

– rw = 6 (4 + 2) = 110

– rx = 5 (4 + 1) = 101

• [rwx][r-x][r--] = [111][101][100] = [7][5][4] = 754

Page 25: The UNIX  File System

owner group others

-rwxrwxrwx-rwxr-xr-x-rw-r--r---r--------

Numerical Access Permissions

111111111 777777

101101111 755755

100100110 644644

000000100 400400

Page 26: The UNIX  File System

Permission Settings: ExamplesUse ls –l to view permission settings-r-- --- --- (400) protect it from accidental editing-rw- --- --- (600) only you can edit/read the file -rw- r-- r-- (644) only you can edit, others can read-rw- rw- rw- (666) public read file!

dr-x r-x r-x (555) anyone can list but can’t create/delete/rename files

dr-x --- --- (500) only you can listdrwx --- --- (700) you can do anything, but not othersdrwx r-x r-x (755) you can do anything, others only listdrwx rwx rwx (777) anyone can do anything!

Page 27: The UNIX  File System

Changing Permissions

chmod command is used to modify permissions.can only be used by the owner of a file/dir

(or the administrator root).

Format:

chmod [ugoa] [+-=] [rwx] [file/dir]

– 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 28: The UNIX  File System

chmod Examples

• Character Method$ chmod a=r-x file$ chmod u=rw- file$ chmod ugo+r file$ chmod go-w file

• Numerical Method$ chmod 744 file$ chmod 600 file

Page 29: The UNIX  File System

Default Permissions

• Every time a directory or file is created it must immediately have some permissions

• The umask instruction sets the default permissions

$ umask ddd• ddd is a three digit octal number

Page 30: The UNIX  File System

umask• The system’s initial permission value, used when a file

is created, is 666 (rw-rw-rw-).

• The system’s initial permission value used when a directory is created, is 777 (rwxrwxrwx).

• To determine the umask value you want to set, subtract the value of the permissions you want from the initial permissions. The remainder is the value to use with the umask command.

• To change the default mode for files to 644 (rw-r--r--), subtract 644 from 666. You get 022, which is the value you would use as an argument to the umask command.

Page 31: The UNIX  File System

File and Directory Permissions for umask Values

unmask Octal Value File Permissions Directory Permissions

0 rw- rwx

1 rw- rw-

2 r-- r-x

3 r- r--

4 -w- -wx

5 -w -w-

6 --x --x

7 --- --- (none)

Page 32: The UNIX  File System

umask Scope

• The new umask value affects only those files and directories that are created from this point forward.

• Place a umask command in your .profile file to permanently set your default permissions.

Page 33: The UNIX  File System

The SuperUser

• Every Unix system has at least one userid which is special

• This is referred to as root although the name may be different

• root may access any and all files or directories, no matter what their protection bits are set to

Page 34: The UNIX  File System