- r - read, allows you to read the contents of a ﬁle
- w - write, allows you to write to a ﬁle or delete it
- x - execute, allows you to run a ﬁle as a script, or cd to a directory.
- User or Owner is the person who created the ﬁle
- Group is the group that the owner belongs to
- Other is everyone else in the world.
ls -l readmemight give the results:
-rw-r--r-- 1 bob staff 0 Jun 17 23:30 readmeThis shows that the file readme is owned by user bob and group staff. The permissions are shown by the sequence of ten characters at the start of that line: -rw-r--r--. The first character is a - for a file. Alternatively if it were a d it would indicate a directory. The next three characters (rw-) indicate the permissions for the owner of the file (bob). The next three characters (r--) indicate the permissions for a user who is not the owner of the file, but who is in the group (staff) that owns the file. The last three characters (r--) indicate the permissions for everyone else.
You can remove a read-only file from a directory only if you have write permission for that folder (-rw-r--r--). Typically directories must have execute permission if you want people to have read permission.
To change the permissions on a file or folder, use the chmod command. For details, see man chmod. The easiest way to change permissions is to use the symbolic modes where the permission changes are specified by add +, remove -, or set = permissions. Use u to indicate that the change applies to the user permissions, g to indicate that it applies to the group permissions, and o for anyone else.
To change the permissions on the file readme to allow the world to have write permission:
chmod o+w readme
If the file isn't owned by the user, preface the command with sudo and supply a superuser password:
sudo chmod g+w readmeTo add executable permission to the file (e.g. because it is a script) for the owner of the file and for users in the group that owns the file use:
chmod ug+x readme
To remove the read and write permissions for the group and the world:
chmod go-rw readme
Use the the set = operation to set the permissions to an exact configuration - without regard to what the permissions are currently. To set the file to be readable and writable by the owner, but only readable by group and "other":
chmod u=rw,go=r readme
Things work similarly for directory permissions. Often you want to change the permissions of a directory and all its contents. Do this with the -R option to chmod.
To change a directory and all its contents to be writable by the owner and group use:
chmod -R ug+w Folder
Likewise, the flag X (uppercase) can be combined with the -R option to ensure that a folder and all of its sub-folders have execute permission, but not the files. Typically execute permission is not desirable for files unless they are applications or scripts.
chmod -R ugo+X Folder