To change file permissions on Linux, you can use the
chmod command. The
chmod command allows you to modify the read, write, and execute permissions for the owner, group, and others.
Here is the basic syntax for the
chmod options permissions filename
- -v: Verbose mode, displays a message for each file processed.
- -c: Like verbose mode, but displays a message only if a change is made.
- -R: Recursively change permissions for directories and their contents.
- u: User/owner permissions.
- g: Group permissions.
- o: Other (everyone else) permissions.
- a: All permissions.
Permissions can be specified using two different methods:
- Symbolic method:
+ adds permissions.
- removes permissions.
= sets permissions explicitly.
r for read permission.
w for write permission.
x for execute permission.
- Numeric method:
Each permission has a numeric value.
4 for read permission.
2 for write permission.
1 for execute permission.
- To give read, write, and execute permissions to the owner of a file:
chmod u+rwx filename
- To remove read and write permissions from the group and others:
chmod go-rw filename
- To give read and execute permissions to all users:
chmod a+rx filename
- To recursively change permissions for all files and directories in a directory:
chmod -R u+rwx directory
Note: You will need appropriate permissions or superuser (root) privileges to change permissions on files/directories you don't own. Be careful while altering permissions for system files.