Translate

How to view and edit file permissions in Linux using chmod (easy method)

This post is for all my frends who are still having problems with changing file permissions in linux.

 Checking or viewing the current permissions for a file:

you can do this by right clicking and selecting properties in the file manager,but this method is not suitable
if you want to view permissions of a lot of files.
just go to the folder of the file using cd or launch konsole from the file browser

type:ls -l

each file will be displayed by preceding the file permissions and other details
like this;

-rw-rw-r--  1 ab ab 7878716 Sep  7 16:40 Beautiful-ringtone.wav
drwxrwxr-x  2 ab ab    4096 Sep 11 17:28 blog/

the first character is d then it is a directory,if it is hyphen then it is a file,
next three letters are the permissions for the user/creater (here it is ab)of the file (r,w,x where r is reading ,w writing,x executable)if a hyphen is shown then that permission is not given.
next 3 letters are the permissions for the user group (here it is ab) and next 3 characters are showing the permissions for other users.

Changing permissions for a file/directory:

just go to the folder of the file using cd or launch konsole from the file browser
*note: you must be logged as root ,if you want to change the permissions for root owned files
 type : chmod who=permissions filename

you can replace who with u,g,o,a where u is for the user or owner of the file,g is the group of the owner and other users,
o is for other users,a is for all users.
 replace permissions with the r,w,x where r is reading ,w writing,x executable

eg :chmod a=rw mydoc.txt
 now my doc can be read and edited by all users.

but if you dont want others to read or write your mydoc.txt ,then leave a blank space for permission eg:

chmod o= mydoc.txt

you can also change the permissions of one user as the permission of another user i.e,
chmod o=u mydoc.txt
 to assign the user/owner permission to other users

Changing File Permissions of all the files and folders in a folder/directory:

adding a small variation in the above command (by adding -R after chmod)
can change file permissions for all the files and folders in a directory
Eg:
chmod -R rw documents

********************************************************************************
There are various other ways like +,- ,using numbers for giving permissions etc......which can be a little confusing for a new guy so i have avoided it :)

urs Ab

Categories:

Leave a Reply