This blog post explains how to Change Permissions in Linux using the symbolic method. It includes examples of how to add, remove, and modify permissions for the owner, group, and others.
Change Permissions – Symbolic Method
- To change access modes:
- chmod [-OPTION]…. mode[,mode] file|directory ….
- mode includes:
- u,g or o for user, group and other
- +- or = for grant, deny or set
- r, w or x for read, write and execute
- Options include:
- -R Recursive
- -v Verbose
- –reference Reference another file for its mode
- Examples:
chmod ugo+r file:
Grant read access to all for filechmod o-wx dir:
Deny write and execute to others for dirchmod --reference file 1 file2
: Get the mode from file1 and place it on file2
chmod Syntax
The chmod command changes access mode for files and directories. The chmod command takes a permission instruction followed by a list of files or directories to change. The permission instruction can be issued either symbolically (the symbolic method) or numerically (the numeric method).
Using the symbolic method, the permission expression contains three fields: an indicator of who has access to the file, an operator for selecting how the permissions could be changed, and a permission. If no who value is given, then the permission is added or removed for user, group and other. Multiple, comma separated operations can be given in a single command.
Who may be | operator may be | permissions may be |
u User who owns the file | + Add a permission | r Read |
g Users in the file’s Group | – Remove a permission | w Write |
o Other users | = Assign a permission | x Execute or cd |
a All three categories | s Set user ID bit or group | |
t Sticky bit (for directories) |
Examples: –
chmod u+w,go-w .bashrc
grants write access to owner but denies it to group and other.chmod u=rw .bashrc
sets user permissions to read and write, with execute turned off, regardless of the current permissionschmod +r .bashrc
makes the file world-readable
A useful option to chmod is -R (recursive). This option tells chmod to traverse an entire directory tree to change the permissions of all its files and subdirectories. The s and t permissions will be discussed in a later unit.