-A +A
  Total Views: 17352

How can I change the file and directory permissions in Unix operating system with the 'chmod' command?

In the Unix operating system, "ls" command displays the names of directories and file names. The user can also view the files according to his/her preferences from among some command options.

-a Displays all the content of the directory including the hidden files beginning with '.'
-l Lists files and gives details about them
(date of last process, file permissions )
-t Lists the files according to the dates when these files are last modified.
-R Lists all the files including the contents of subdirectories.

In Unix, there are file permissions like read, write and execute for three categories of users, namely, file owner, group and others. The file permissions that are assigned to a file can be displayed with "ls -l" command.

 

bash-2.03$ ls -l
total 100
-rw------- 1 usrname usrgrp 1156 Nov 29 14:30 a_file
-rw-r--r-- 1 usrname usrgrp   11 Dec 19 17:29 file1
drwx------ 2 usrname usrgrp  512 Nov 29 14:44 mail
drwxr-xr-x 5 usrname usrgrp  512 Nov 29 11:56 wwwhome

 

A closer look at the screen above will show that there are seven basic columns.

1 2 3 4 5 6 7
drwxr-xr-x 5 username usergroup 512 Nov 29 11:56 wwwhome

1st Column This column shows the read, write and execute permissions of wwwhome directory. It includes 10 characters.

 

The first character in the permission sequence "drwxr-xr-x" can be "-", "d" or "l" and these characters simply signify "file", "directory" and "link" respectively.

The remaining nine characters are grouped three by three. The first group signifies the owner's permissions, the second group signifies the group's permissions and the third group signifies other users' permissions.

The three characters in these three groups signify respectively the read, write and execute permissions of all categories of users.

2nd Column; This column displays the number of links that are working in a file. The number of links for a directory indicates the total of links present in this directory and the directories linked to this directory.

3rd and 4th Columns; This column displays the user code and the group which the user belongs to,

5th Column; This column displays the size of the file or the total character number reserved for a file,

6th Column; This column displays the date when the last modification on the directory took effect,

7th Column This column displays the name of the directory or file.

The read, write and execute permissions are specified or modified solely by the owner of the file. The permissions assigned to a file can be modified buy the "chmod" command. The command sequence is as follows;

chmod [permissionmode] [filename]

Permission mode is comprised of the category characters, permit/prohibittance characters and the characters showing type of the permission. '+' sign gives file permissions, '-' sign omits the file permission. The file name is the name of the file whose file permissions would be changed. For example:

bash-2.03$ chmod go-x wwwhome   1
bash-2.03$ ls -l wwwhome        2
total 102
drwxr--r-- 2 username usergroup 512 Nov 29 11:56 wwwhome

"chmod go-x" command is executed for the "wwwhome" directory on line 1 in the above example. In the second line, "ls -l"command checks the permissions of "wwwhome" directory. Apparently, no one other than the owner is permitted to write into and execute "wwwhome" any longer.