Pick a Free OS

User login


Understanding Linux file permissions

chmod g+wx,o-rwx somefile

Group members have been given write and execute access but all access has

been removed for users that are not members of that group. File

permissions now are -rwxrwx---.

chmod a+x somefile

Give everyone execute access. Permissions now are -rwxrwx-x. Specifying

'a' here is not essential. You could simply say '+x' here; 'all' is

assumed by default. So, the command chmod +x somefile is equivalent to the

one above.

chmod go-rx somefile

If the same permission bits are to be set/unset for users, groups or

others then you can club them together as above. File permissions now are


chmod ug=rwx somefile

This sets the file permissions to exactly what is specified. Now, the file

permissions become -rwxrwx---.

chmod o=g somefile

File permissions for others are set at what the permissions for group are

set. Permissions now are -rwxrwxrwx.

There is another way in which you can specify the file permissions. The

permission bits r,w and x are assigned a number.

r = 4

w = 2

x = 1

Now you can use numbers, which are the sum of the various permission bits.

E.g - rwx will be 4+3+1 = 7. rx becomes 4+1 = 5. The chmod command now


chmod xyz filename

where x,y and z are numbers representing the permissions of user, group

and others respectively. Each number is the sum of the permissions to be

set and are calculated as given above.

Chmod 644 somefile

6 = 4 + 2 = rw

4 = r

4 = r

As you can see, the permissions for somefile are being set to -rwr--r--.

This is a simpler and quicker way of setting the file permissions. Refer

to the table below as a quick reference.

0 - ---

1 - --x

2 - -w-

3 - -wx

4 - r--

5 - r-x

6 - rw-

7 - rwx

In addition to the file permission, you can also modify the owner and

group of the file. The chown program is used here and its syntax is very

simple. You need to be the owner of a file or root to do this.

chown new-owner somefile

chown newbie somefile

To change group, user the chgrp command. Syntax is similar to chown. You

will need to be the owner of the file and also belong to the same group as

the file, or you should be root.

chgrp new-grp somefile

That was a quick look at file permissions under Linux. If you ever face a

problem under Linux, just take a look at the file permissions. In any