Thanks to visit codestin.com
Credit goes to www.geeksforgeeks.org

Open In App

chmod Command in Linux with Examples

Last Updated : 04 Nov, 2025
Comments
Improve
Suggest changes
31 Likes
Like
Report

The chmod (change mode) command in Linux/UNIX is used to set or modify file and directory permissions. Every file in Linux has an owner, a group, and associated permissions that determine who can read, write, or execute the file. Using chmod, Administrators and users can control these permissions to ensure proper access and security. Let's consider the example

Use the chmod command by giving the permission 745

Command:

chmod 745 newfile.txt

Output:

chmod

Breakdown of -rwxr--r-x:

  • Owner (7): rwx > read, write, execute
  • Group (4): r-- > read only
  • Others (5): r-x > read & execute

Here, the file is:

  • Fully accessible (read/write/execute) by the owner
  • Read-only for the group
  • Read + execute for others

Syntax of the chmod command

chmod [options] [mode] [File_name] 

Here,

  • Options: Optional flags that modify the behavior of the chmod command.
  • Mode: The permissions to be set, represented by a three-digit octal number or symbolic notation (e.g., u=rw,go=rx).
  • File_name: The name of the file or directory for which the permissions are to be changed.

Options Available in chmod Command Linux

Here Are Some Useful Options of the chmod Command in Linux

ModeOwnerGroupOthersTypical use for scripts
700rwx------Private script (only you can run/edit).
711rwx--x--xExecutable/traverse only; contents not readable.
744rwxr--r--You edit & run; others can read (not execute).
750rwxr-x---Team-only executable; hidden from others.
754rwxr-xr--Exec for group, read-only for others.
755rwxr-xr-xCommon: everyone can run, only you edit.
775rwxrwxr-xShared within a group (both owner & group can edit/run).

Note: Options in `chmod` are basically used for making changes in bulk and modifying permissions across multiple files or directories at once.

Key Permission Types:

In Linux, permissions determine who has control over a file or directory. These permissions specify who can read (access), write (edit or delete), or execute (run) a file, based on user roles: owner, group, and others.

  • Read (r): Allows viewing the contents of the file.
  • Write (w): Allows modifying the file or directory.
  • Execute (x): Allows running the file as a program or entering the directory.

Examples of Using the Octal mode:

Suppose if we to give read and write permission to the file Owner. Read, write and executable permission to the Group. Read-only permission to the Other. They our command would be.

chmod 674 [file_name]

Here.

  • 6 represent permission of file Owner which are (rw-).
  • 7 represent permission of Group which are (rwx).
  • 4 represent permission of Other which is (r--).

Note: You can view and calculate file permissions such as who can access, read, write (delete or modify), or execute a file for the Owner, Group, and Others (Public) using a chmod calculator.

calculator

Here, we use a calculator to view the permissions. For example, the owner has read, write, and execute permissions, while the group and others (public) have only read and write permissions, but cannot execute the file.

Equivalent Numeric Permission:

Syntax:

chmod 766 filename

Table:

User TypePermissionsBinaryValue
Ownerrwx1117
Grouprw-1106
Othersrw-1106

Example of Reverting Changes Made by "chmod" Command in Linux

To undo or revert changes made by "chmod" command in Linux , we can use the `chmod` command again but this time we should mention the correct permission we want. 

 Here are the steps to undo or revert changes:

  • Determine the correct permission you want and use `chmod` command again. 
    For Example: If we want to revert the changes to "rw-r--r--" (read and write permission for owner, read-only permission for group and others), according to this our octal value would be "644" (read = 4, write=2).
  • Now open the directory and write the given command :
chmod 644 [file_or_directory_name]

Here instead of "[file_or_directory_name]" use your file or directory name.

Suppose our file name is "a.txt"

Before reverting or undo changes:

ls -l a.txt
ls -l a.txt   (used to display all the permission a.txt has)

After reverting or undo changes:

reverting of chmod changes in Linux
Here we can see that changes has be done

Practical Implementaion of How to Make script executable in Linux

In Linux, scripts are typically written in languages like Bash, Python, or Perl. While the script's content is crucial, ensuring it has executable permissions is equally important. Without execution permissions, Linux won't allow the script to run.

Step 1: Navigate to the Script's Directory

Open the terminal and use the cd command to navigate to the directory where your script is located.

For example:

cd /path/to/your/script

Step 2: Check Current Permissions

Use the `ls` command with the `-l` option to list the files in the directory along with their permissions. This step helps you identify the current permissions of your script:

ls -l
checking current permission
checking current permission

Step 3: Make the Script Executable

To make a script executable, you need to use the `chmod` command. Assuming your script is named `example.sh`, you can make it executable with the following command:

chmod +x example.sh

This command adds the execute (+x) permission to the script.

Step 4: Verify Changes

Run the `ls -l` command again to verify that the script now has execute permissions. You should see an 'x' in the permission field for the script:

ls -l
verifying changes after making script executable
verifying changes after making script executable

Step 5: Execute the Script

Now that your script has executable permissions, you can run it using the `./` notation followed by the script's name. For example:

./example.sh
execute the script
execute the script

This notation tells Linux to look in the current directory (.) for the script named example.sh.


Explore