how to use chmod command in linux with its examples

The chmod command is used in Unix-like operating systems, including Linux, to change the permissions of files and directories. It stands for “change mode”. This command comes from th package “coreutils-x.x.x”.

Examples:

1. To change the permission of a file to 755 with chmod,

# chmod 755 test.txt

2. To update permission of a file and get to know if the permissions are applied or not, its like a verbose mode,

# chmod -c 755 test.txt

3. To change the file permission with verbose mode, you can run below command,

# chmod -v 750 test.txt

4. If you want to suppress the error messages coming while running the commands then run with, so assume there is “test.txt” file present under the current path, then ideally it should throw error as “chmod: cannot access ‘test.txt’ : no such file or directory”, but when used with “-f” switch, it will suppress that error messages.

# chmod -f 700 test.txt
# chmod –silent 700 test.txt
# chmod –silent 750 testtxt

5. Sometimes you want to apply the mentioned file permissions inside the child files or directories from the mentioned directory, in that case you can run below command. Here we are trying to change the permissions for a directory “MyDirectory” from “/tmp”.

# cd /tmp/
# chmod -R 755 MyDirectory/

chmod command not found

Incase you face a situation, where system gives you a message as “chmod command not found”, then you do not have package from which this utility is provided. Hence please follow below steps to install the package.

OS VersionCommand to install
RedHat / CentOS / Fedorayum install coreutils
Debian / Ubuntu / Kubuntuapt install coreutils

chmod command in Linux with 777 or full access

Inorder to give full permission i.e. 777 for any folder of file, then it can be done with below command,

# chmod 777 test.txt

Note: This will give full access to this file.

chmod command in linux to change directory permissons

To change the permission of any directory of folder we can use the same command with directory name.

# chmod -R 755 MyDirectory/

Leave a Reply

Your email address will not be published. Required fields are marked *