You are on page 1of 6

29/09/2010

Introduction
The UNIX filestore

The UNIX Filestore


Gail Hopkins

Files and directories File handling commands File Permissions

Files
From the users point of view, all information on the computer is stored in files Files may contain many kinds of information, including programs, data and documents Like paper files, they have a name (chosen by the user) and some content By convention, the filename suffix suggests the type of content

Example files
Myfile.doc = Microsoft Word Document Myfile.xls = Microsoft Excel Document Myfile.ppt = Microsoft PowerPoint Document Myfile.mdb = Microsoft Access Document Myfile.txt = Text file (Notepad) Myfile.jpg, Me.bmp, Me.gif = Picture or image files Myfile.wav, mp3, wmp = Sound files Myfile.html = HTML web page file Myfile.zip = Zipped or compressed file Myfile.exe = Application file Myfile.log = Log file

Directories
Files are stored in directories (folders) Each directory may contain many files and also other directories By convention, directory names do not usually have suffixes

The filestore
There is a single hierarchical filestore that is shared by all users It is spread over the network, may involve many disks on may different computers and may even be linked to other filestores

29/09/2010

Each user has their own personal area that starts at their home directory There are also common areas for programs, projects and administration The filestore starts at the root directory At any time, as they use the system, a user is in a current directory from which they give commands to access files When they first log on, the current directory is set to their home directory

The filestore

The filestore
(root) staff xxx gtr xxx usr bin itmasters stud ug pg xxx04u CUA etc

Research Teaching Private CUA Lecture1.ppt Lecture2.doc MVR

xxx02u .profile

Coursework1.txt

File handling commands Viewing File Contents


The cat [filename] command displays the contents of the named files
i.e. it reads the contents of the file(s) and outputs to the shell window
with no arguments cat simply echoes back what you type at the keyboard there is no scrolling with the cat command

Viewing File Contents (2)


head displays the first 10 lines of a file tail displays the last 10 lines of a file

more [filename] lets you scroll through a file


also less [filename]

Absolute and Relative Pathnames


There are two ways of specifying filenames
from the current directory - relative pathnames from the root directory - absolute pathnames

Where am I in the File Structure?


pwd prints the pathname of the current directory cd pathname changes current directory
with no argument it goes to the home directory

Simple pathnames consist of sequences of names separated by / characters


An example of a relative pathname:
../myDoc.txt

An example of an absolute pathname:


/stud/ug/xxx04u/Documents/myDoc.txt

29/09/2010

Where am I in the File Structure? (2)


(root) staff xxx gtr xxx usr bin itmasters stud ug pg xxx04u CUA robin$ pwd /stud/ug/xxx04u/CUA robin$ cd .. robin$ pwd /stud/ug/xxx04u/ etc robin$ pwd /stud/ug/xxx04u robin$ cd CUA robin$ pwd /stud/ug/xxx04u/CUA

ls [pathname] lists the contents of the named directories


with no argument, the current directory is listed

File handling commands Viewing and Changing Directory Contents

Research Teaching Private CUA Lecture1.ppt Lecture2.doc MVR

xxx02u .profile

mv pathname1 pathname2 changes the name of pathname1 to be pathname2 (e.g., to move files
if pathname2 already exists, then its previous contents are lost if not, then it is created

Coursework1.txt

File handling commands Viewing and Changing Directory Contents (2)


cp pathname1 pathname2 copies the contents of pathname1 to pathname2
if pathname2 already exists, then its previous contents are lost if not, then it is created

File handling commands Manipulating Directories


mkdir pathname ... creates a new directory
it fails if they already exist
robin$ mkdir fred robin$ mkdir fred mkdir: failed to make directory fred; File exists

rmdir pathname removes directories


it fails if they are not empty
robin$ rmdir fred rmdir: directory fred: Directory not empty

rm pathname removes files but not directories (be careful)

Printing
lpr pathname prints files
it goes to your default printer you can specify a printer with the -P flag, for example lpr -Phet fred.ps
do not send text files and program listings to laser printers do not send postscript files to line printers!

More about pathnames


Special symbols can be used in pathnames .. the directory one level above this ../.. the directory two levels above this . the current directory ~ this users home directory ~user a specific users home directory * wildcard matching any string ? wildcard matching any single character

Most of these commands have many flags for specifying different options

29/09/2010

Relative and Absolute Pathnames Revisited


Relative
(root) staff xxx gtr xxx usr bin itmasters stud ug pg

Security and file permissions


A shared filestore needs a security mechanism to prevent the unauthorised reading and writing of files UNIX associates a permissions list with each file saying who can do what to it Each directory also has a permissions list How you can access a file depends upon its permissions list and those of all its parent directories

Absolute /
/stud /stud/ug /stud/ug/xxx04u ~ ~xxx04u

../../../..
../../.. etc ../..

Research Teaching Private CUA Lecture1.ppt Lecture2.doc MVR

xxx02u .profile

xxx04u .. CUA

/stud/ug/xxx04u/CUA

You are here!

Coursework1.txt

Permissions lists
Specify who can do what There are three kinds of who: u the user (owner) g members of the users group o others - anyone else There are three kinds of what: r read w write x execute

Permissions lists (2)


Use ls -l to see permissions lists
drwxr--r-Drwxr--r--rw-r--r--rw-r----1 1 1 1 gtr gtr gtr gtr staff staff staff staff 173568 202752 2638848 87552 Sep 21 15:41 Labs Sep 21 17:43 Lectures Oct 6 18:58 Outline.doc Oct 6 18:19 Intro.ppt

Permissions lists (3)


Each permissions list is shown as ten characters:
Directory

Groups permissions (read only) Group that User user is in


1 1 1 1 gtr gtr gtr gtr staff staff staff staff

type d -

user rwrwx rw-

group r---rw-

other r---rw-rwxr--r-Drwxr--r--rw-r--r--rwxr--r--

Date file was last modified/created


5173568 202752 2638848 5587552 Sep 21 15:41 cve_user Sep 21 17:43 Reports Oct 6 18:58 Yr1Report.doc Oct 6 18:19 plod_node_mgr

Users permissions (read, write and execute)

Others permissions (read only) File size File/Directory name

29/09/2010

The effect of directory permissions


Execute lets you change (cd) into that directory
(i.e. you are searching the directory) other parents up to the root

Read lets you list files in the directory


(i.e. you are reading the directory contents)

execute permission controls whether any files and directories below this point can be accessed at all permissions control whether files can be accessed at all, listed, created and deleted

Write lets you create and delete files


(i.e. you are writing to the directory contents)

parent directory

To use a file at all you must have execute permission on all of its parents (otherwise it is as if it doesnt exist)

file

permissions control specific actions on this file

chmod mode pathname is used to alter permissions lists Mode specifies a sequence of changes, each of the form who operation permission
who is u, g or o operation is + (grant) or - (revoke) permission is r, w or x

Setting and changing permissions chmod

Setting and changing permissions chmod (2)


The mode can also be a three digit octal number that is interpreted as a sequence of nine bits to set the whole permissions list at once:
chmod 644 progress.txt
644 is 110 100 100 which is interpreted as rw- r-- r--

chmod 777 progress.txt


777 is 111 111 111 which is interpreted rwx rwx rwx

Examples:
chmod o-r g-r plan.doc chmod u+rwx Admin

chmod 400 progress.txt


400 is 100 000 000 which is interpreted as r-- --- ---

Setting and changing permissions chmod (3)


Files are created with a default permission
usually -rw- r-- r-depends upon the command used to create the file set using the umask command

Further reading
TSG`s guide for students:

http://support.cs.nott.ac.uk/help/docs/shells/
Using text editors (particularly emacs and vi):

http://support.cs.nott.ac.uk/help/docs/emacs/
Using the X Window system:
http://support.cs.nott.ac.uk/help/docs/xwindow/x-usage

29/09/2010

Summary
The UNIX filestore Pathnames Security and file permissions

You might also like