This article covers both the symbolic and numeric mode of the chmod command. Control who can access files, search directories, and run scripts using the Linux's chmod command. This command helps modifies Linux file permissions.
In Linux, who can do what to a file or directory is controlled through sets of permissions. There are three sets of permissions. One set for the owner of the file, another set for the members of the file's group, and a final set for everyone else.
To change directory permissions in Linux, use the following:
- chmod +rwx filename to add permissions.
- chmod -rwx directoryname to remove permissions.
- chmod +x filename to allow executable permissions.
- chmod -wx filename to take out write and executable permissions.
We can use the -l (long format) option to have ls list the file permissions for files and directories.
$ ls -l
chmod Numerical Shorthand:
- 0: (000) No permission.
- 1: (001) Execute permission.
- 2: (010) Write permission.
- 3: (011) Write and execute permissions.
- 4: (100) Read permission.
- 5: (101) Read and execute permissions.
- 6: (110) Read and write permissions.
- 7: (111) Read, write, and execute permissions.