chmod command

(change file permissions)

The chmod command is used to change access permissions to files and directories.
The format is chmod permissions filename

> chmod 755 file.txt

To see what permissions a file or directory has in linux, you use the ls command with option -l (eg: ls -l) which gives a long format listing.

> ls -l
-rwxr--r-- 1 root root 765 Apr 23 09:22 file.txt

The permissions are the first 10 characters of the line (-rwxrwx---) and can be broken down as follows.

-
rwx
r--
r--
1
root
root
765
Apr 23
file.txt
File type
Owner
Group
All
Links
Owner
Group
Size
Mod date
Filename

The r,w and x stand for...
r = read
w = write
x = execute

The first character on the line shows what type of file or directory it is, and can be one of these things...
- = file
d = directory
l = symbolic link
b = block-type special file
c = character-type special file
p = named pipe
S = socket
s = XENIX semaphore
m = XENIX shared data (memory) file
D = Solaris door
n = HP-UX network special file

The remaining 9 characters are broken down into 3 groups of 3 characters. The first three are the permissions for the owner, the middle three are permissions for the group which has access to the file and the last three are the permissions for everybody else.

 

Back to index

Subscribe to us on YouTube