File Permissions


Files in Linux have certain specified file permissions. These permissions can be viewed by running the ls -l command on a directory or on a particular file. For example:

ls –lfilename

-rwxr-xr-x 1 barry user 1643 Jan 19 23:23 filename

If you look close at the first 10 characters, you have a dash (-) followed by 9 more characters. The first character describes the type of file.

A dash (-) indicates a regular file. A "d" would indicate a directory, and "b" a special block device, etc.

First character ofls -loutput: -= regular file d = directory b = block device c = character device

l = link

The next 9 characters indicate the file permissions. These are given in groups of three:

OwnerGroupOthersrwx rwx rwx

The characters indicate

r = read w = write

x = execute

So in the above_filename_we have

-rwx r-x r-x

This gives the file owner read, write and execute permissions (rwx), but restricts other members of the owner’s group and users outside that group to only read and execute the file (r-x).

Now back to the chmod command. There are a number of ways to use this command, including explicitly assigning r, w, or x to the file. We will cover the octal method here because the syntax is easiest to remember

(and I find it most flexible). In this method, the syntax is as follows

chmodoctal filename


_octal_is a three digit numerical value in which the first digit represents

the owner, the second digit represents the group, and the third digit represents others outside the owner's group. Each digit is calculated by assigning a value to each permission:

read (r) = 4 write (w) = 2 execute (x) = 1

For example, the file_filename_in our original example has an octal permission value of 755 (rwx =7, r-x =5, r-x=5). If you wanted to change the file so that the owner and the group had read, write and execute permissions, but others would only be allowedto read the file, you would issue the command:

chmod 774 filename

4(r)+2(w)+1(x)=7

4(r)+2(w)+1(x)=7

4(r)+0(-)+0(-) =4

A new long list of the file would show:

-rwxrwxr-- 1 barry user 1643 Jan 19 23:23 filename

(rwx=7, rwx=7, r--=4)

results matching ""

    No results matching ""