Вы находитесь на странице: 1из 16

Unit 6

File
Permissions

Objectives
After completing this unit, students should be able to:
List the basic file permissions
Change the basic file permissions using both the
octal and symbolic formats

Long Listing of Files


The ls command with the -l option can be used to obtain more
information about the files in a directory.
$ ls -l
drwxrwxr-x
drwxrwxr-x
-rwxrwxr-x
-rwxrwxr-x

permission
bits

2
2
1
2

team01
team01
team01
team01

staff 1024
staff
512
staff
320
staff
144

Aug
Feb
Feb
Feb

12
18
22
22

10:16 c
09:55 doc
07:30 suba
16:30 test1

File Protection/Permissions
rwx

rwx

rwx

user

group

others

r = read

w = write

x = execute

For an ordinary file:


r => Can look at the contents of a file
w => Can change or delete the contents of a file
x => Can use the file name as a command (r is also needed)

For a directory:
r => Can find out what files are in the directory
w => Can create/remove files in the directory (x is needed)
x => Has permission to be in the directory
(that is, cd to the directory or access files from the
directory)

Changing Permissions (Symbolic Notation)


chmod mode filename
u = owner of the file
g = owner's group
o = other users on the system
a = all

+ : add permissions
- : remove permissions
= : Clears permissions and sets to mode specified

$ ls -l newfile
-rw-r--r-1 team01

staff 58 Apr 21

16:06 newfile

$ chmod go+w newfile


$ ls -l newfile
-rw-rw-rw1 team01

staff 58 Apr 21

16:06 newfile

$ chmod a+x newfile


$ ls -l newfile
-rwxrwxrwx
1 team01

staff 58 Apr 21

16:06 newfile

$ chmod o-rwx newfile


$ ls -l newfile
-rwxrwx--1 team01

staff 58 Apr 21

16:06 newfile

Changing Permissions (Octal Notation)


File and directory permissions can be specified in the symbolic
syntax or as an octal number:
Symbolic
Binary
Octal

User
rwx
111
4+2+1
7

Group
rw110
4+2+0
6

Others
r-100
4+0+0
4

To change permissions so the owner and group have read and


write permissions and others read only:
$ ls -l newfile
-rw-r--r-1 team01

staff 58 Apr 21

16:06 newfile

$ chmod 664 newfile


$ ls -l newfile
-rw-rw-r-1 team01

staff 65 Apr 22

17:06 newfile

Default File Permissions


The default protections for newly created files and directories are:

File

-rw-r--r--

644

Directory

drwxr-xr-x

755

These default settings may be changed by changing the umask value.

umask
umask specifies what permission bits will be set on a
new file or directory when created. It is an octal
number that is used to determine what permission bits a
file or directory is created with:
New Directory: 777 - 022:
New File:
666 - 022:

755
644

=> rwxr-xr-x
=> rw-r--r--

The default value of 022 is set in /etc/security/user. It


can be changed for all users or for a specific user.

Activity: Personal Directories

Activity

Write Permission on a Directory


$ ls -ld /home/team01
drwxrwxrwx 2 team01 staff 512
$ ls -l /home/team01/file1
-rw-r--r-- 1 team01 staff 1300

July 29

9:40

team01

July 30

10:30 file1

$ whoami
team02
$ vi /home/team01/file1
file1: The file has read permission only
$ vi myfile1
Ha! Ha! I changed this file. Figure out how.
$ mv myfile1 /home/team01/file1
override protection 644 for file1? y
$ cat /home/team01/file1
Ha! Ha! I changed this file. Figure out how.

Function/Permissions Required
Command

Source Directory

Source File

Target Directory

cd

N/A

N/A

ls

N/A

N/A

ls -l

r, x

N/A

N/A

mkdir

N/A

N/A

N/A

N/A

cat, pg, more

x
w (parent)
x
w (parent)
x

N/A

mv

x, w

NONE

x, w

cp

x, w

touch

x, w *

NONE

N/A

rm

x, w

NONE

N/A

rmdir

Next Step ...

Exercise 5

Unit 6: Checkpoint
The following questions are for a file called reporta which has the following
set of permissions: rwxr-x r-x
1. What is the mode in octal?
_________________________________________________________
2. Change mode to rwxr- - r- - using the symbolic format.
_________________________________________________________
3. Repeat the above operation using the octal format.
_________________________________________________________
4. Question four is based on the following listing. Assume that the directory
jobs contains the file joblog.
$ ls -lR
total 8
drwxr-xr-x

judy

finance

512

June 5

11:08

jobs

./jobs:
total 8
-rw-rw-r--

judy

finance

100

June 6

12:16

joblog

Can Fred, who is a member of the finance group, modify the file joblog?

Unit 6: Checkpoint (Cont)


5. Question five is based on the following listing. Assume that the
directory jobs contains the directory work, which in turn contains the
file joblog.
$ ls -lR
total 8
drwxrwxr-x

judy

finance

512

June 5

11:08

jobs

./jobs:
total 8
drwxrw-r-x

judy

finance

512

June 5

11:10

work

./jobs/work:
total 8
-rw-rw-r-- 1

judy

finance

100

June 6

12:16

joblog

Can Fred, who is a member of the finance group, modify the file
joblog?

Unit 6: Checkpoint (Cont)


6. Question six is based on the following listing. Assume that the directory
jobs contains the directory work, which in turn contains the file joblog.

$ ls -lR
total 8
drwxr-xr-x

judy

finance

512

June 5

11:08

jobs

./jobs:
total 8
drwxrwxrwx

judy

finance

512

June 5

11:10

work

./jobs/work:
total 8
-rw-rw-r-- 1

judy

finance

100

June 6

12:16

joblog

Can Fred, who is a member of the finance group, copy the file joblog to
his home directory?

Summary
Basic file permissions can be listed using the ls -l
command
chmod grants or removes read, write and execute
permissions for three classes of users: user, group and
others
The permissions used with the chmod command can be
defined in symbolic or octal format
The umask specifies the permissions for new files and
directories

Вам также может понравиться