Earlier we discussed about how to use octal permission bits with chmod. In this article, let us review how to use symbolic representation with chmod.
Following are the symbolic representation of three different roles:
- u is for user,
- g is for group,
- and o is for others.
Following are the symbolic representation of three different permissions:
- r is for read permission,
- w is for write permission,
- x is for execute permission.
Following are few examples on how to use the symbolic representation on chmod.
1. Add single permission to a file/directory
Changing permission to a single set. + symbol means adding permission. For example, do the following to give execute permission for the user irrespective of anything else:
$ chmod u+x filename
2. Add multiple permission to a file/directory
Use comma to separate the multiple permission sets as shown below.
$ chmod u+r,g+x filename
3. Remove permission from a file/directory
Following example removes read and write permission for the user.
$ chmod u-rx filename
4. Change permission for all roles on a file/directory
Following example assigns execute privilege to user, group and others (basically anybody can execute this file).
$ chmod a+x filename
5. Make permission for a file same as another file (using reference)
If you want to change a file permission same as another file, use the reference option as shown below. In this example, file2′s permission will be set exactly same as file1′s permission.
$ chmod --reference=file1 file2
6. Apply the permission to all the files under a directory recursively
Use option -R to change the permission recursively as shown below.
$ chmod -R 755 directory-name/
7. Change execute permission only on the directories (files are not affected)
On a particular directory if you have multiple sub-directories and files, the following command will assign execute permission only to all the sub-directories in the current directory (not the files in the current directory).
$ chmod u+X *
Note: If the files has execute permission already for either the group or others, the above command will assign the execute permission to the user
If you enjoyed this article, you might also like..
|
|
|
|











My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 6 comments… read them below or add one }
I think correct command for the p.3 in accordance with its subject should be
$ chmod u-rw filename, don’t I?
The last one is most handy! Can’t even remember, how many times I tried to remove exec permision from files copyed from M$ systems but not affect directories.
former solution:
for f in `ls -R` ; do [ ! -d "$f" ] && chmod a-x “$f” ; done
and now:
chmod -R a-x,u+X *
big thx
@nardi:
While the first six examples are rather trivial I agree for the last one. I’ve been looking for this solution for months.
chmod -R a-x,u+X * – such a beauty!
thx
The last one is truly great. I’ve always used “find -type d -exec …” for this. I’m a little confused about your note, though. Why would it care about the group permissions?
@Alex
The note is about regular files, that the +X rule is not only affecting directories. See man chmod or try it yourself by hand.
This will set the exec rights:
nardi@kub1x ~/test $ ll file
-rw-r-xr– 1 nardi nardi 56 Jun 13 21:06 file*
nardi@kub1x ~/test $ chmod a+X file
nardi@kub1x ~/test $ ll file
-rwxr-xr-x 1 nardi nardi 56 Jun 13 21:06 file*
This won’t set anything, because regular file “file” is neither a directory nor has any exec bit on.
nardi@kub1x ~/test $ ll file
-rw-r–r– 1 nardi nardi 56 Jun 13 21:06 file
nardi@kub1x ~/test $ chmod u+X file
nardi@kub1x ~/test $ ll file
-rw-r–r– 1 nardi nardi 56 Jun 13 21:06 file
chmod -R a-x,u+X *
this command applyed my vstfd stop please give solution