Operating Systems Lab 05
File and Directory Operations
This lecture covers:
• File and directory permissions in more detail and how these
can be changed.
• Ways to examine the contents of files.
• How to find files when you don't know their exact location.
• Ways of searching files for text patterns.
• How to sort files.
• Tools for compressing files and making backups.
• Accessing floppy disks and other removable media.
File and Directory Permissions
• Three types of permission
– Read (r)
– Write (w)
– Execute (x)
• Three categories of users
– User/owner (u)
– Group (g)
– Others (o)
File and Directory Permissions
Permission File Directory
Read (r) User can look at the User can list the files in
contents of the file the directory
Write (w) User can create new
User can modify the files and remove existing
contents of the file files in the directory
Execute (x) User can change into
the directory, but
cannot list the files
User can use the unless (s)he has read
filename as a UNIX permission. User can
command read files if (s)he has
read permission on
them.
Modify Permissions
• File and directory permissions can only be modified by their
owners, or by the superuser (root), by using
the chmod system utility.
• chmod (change [file or directory] mode)
$ chmod options files
• Chmod options [accepts in two forms]
1. Using Octal digits.
2. Using symbols.
1. Modify Permissions Using Octal Digit
• Permissions may be specified as a
sequence of 3 octal digits [0-7]
Permission Digit
• Example:
--- 0
chmod 600 private.txt --x 1
-w- 2
-wx 3
sets the permissions on private.txt to
r-- 4
rw------- (i.e. only the owner can read r-x 5
and write to the file). rw- 6
rwx 7
2. Modify Permissions Using Symbol
• Permissions may be specified Symbol Meaning
symbolically, using the symbols. u User
g Group
• $ chmod ug=rw,o-rw,a-x *.txt o Other
a All
r Read
• sets the permissions on all files
w Write
ending in *.txt to rw-rw---- (i.e. the
owner and users in the file's group x Execute
can read and write to the file, while + Add
the general public do not have any permission
sort of access). -
Take away
permission
Assign
=
permission
• chmod also supports a -R option which can be used to
recursively modify file permissions, e.g.
• $ chmod -R go+r play
• will grant group and other read rights to the
directory play and all of the files and directories within play.
Modify Permissions Using Octal Digit
Modify Permissions Using Symbol