---
title: "Manage Directory and File Permissions with Chmod Recursive"
description: "Learn how to leverage the powerful chmod recursive command to ensure correct permissions across all of your files and folders!"
canonical: "https://adamtheautomator.com/chmod-recursive/"
---

# Manage Directory and File Permissions with Chmod Recursive

> Learn how to leverage the powerful chmod recursive command to ensure correct permissions across all of your files and folders!

Source: https://adamtheautomator.com/chmod-recursive/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Manage Directory and File Permissions with chmod Recursive](https://adamtheautomator.com/wp-content/uploads/2021/12/Manage-Directory-and-File-Permissions-with-chmod-Recursive.jpg)

# Manage Directory and File Permissions with chmod Recursive

[![](https://secure.gravatar.com/avatar/b86598dfae13b031138178564fd0a098edf67927487bbaa32a7d6cc8c6f43792?s=192&d=mm&r=g)Matt Nikonorov](https://adamtheautomator.com/author/matt-nikonorov/)21 December 20217 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)[Linux Shell Scripting](/tag/linux-shell-scripting/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Learning About Linux Users and Groups](#learning-about-linux-users-and-groups)
*   [Understanding Linux File and Directory Permissions](#understanding-linux-file-and-directory-permissions)
*   [Changing File Permissions via the chmod recursive Command](#changing-file-permissions-via-the-chmod-recursive-command)
*   [Setting File Permissions via Numeric Values](#setting-file-permissions-via-numeric-values)
*   [Removing and Adding File Permissions](#removing-and-adding-file-permissions)
*   [Recursively Changing File and Directory Permissions](#recursively-changing-file-and-directory-permissions)
*   [Defining File and Folder Behavior via Special Permissions](#defining-file-and-folder-behavior-via-special-permissions)
*   [Setting the SUID (User + S) Permissions](#setting-the-suid-user--s-permissions)
*   [Setting the SGID (Group + S) Permissions](#setting-the-sgid-group--s-permissions)
*   [Changing the Sticky Bit Permission](#changing-the-sticky-bit-permission)
*   [Conclusion](#conclusion)

Are you tired of having to change file and directory permissions manually? Are you looking for a faster, more efficient way to modify your files and directories permissions? If so, then you’ve come to the right place because, in this article, you will learn how to change file and directory permissions using the command `chmod` recursively!

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

Read on to learn more!

## Prerequisites

To follow along, you need a Linux device and a directory whose files and sub-directories permissions are available to practice with.

## Learning About Linux Users and Groups

Owners and groups are important in Linux, necessary to securely manage files and directories. The owner is to whom a file or directory is assigned, which is the creator, by default. In Linux, files and directories also belong to groups. Both users and groups are set via the [`chown` command](https://manpages.ubuntu.com/manpages/trusty/man1/chown.1.html).

In the screenshot below, the content highlighted in green shows the user who owns the file or directory, `mihail` in this example. The content highlighted in blue shows which group the file or directory belongs to, owned by the `staff` group in this example.

![Listing the owner and group of a set of files and directories](https://adamtheautomator.com/wp-content/uploads/2021/12/image-158.png)

Listing the owner and group of a set of files and directories

Related:[A Windows Guy in a Linux World: Users and File Permission](https://adamtheautomator.com/linux-file-permissions/)

## Understanding Linux File and Directory Permissions

Permissions set what actions a user or group may perform on a given file or directory. They are indicated by a character representation and also assigned a numerical value.

*   **Read (`r`** or `4`**):** Indicates whether a user or group may read the contents of the file or directory. The read permission is granted by default to all newly created files and directories for all parties.
*   **Write (`w`** or **`2`):** Indicates whether a user or group can edit the contents of an object. This permission is granted by default only to a file or directory owner.
*   **Execute (`x`** or **`1`):** Indicates whether a user or group can execute a file or execute commands inside a directory. The execute permission is granted by default only to directories but not to files.

> _If you do not give the user (`u`) execute permissions to a directory, they will not be able to list contents as the user will not be able to execute commands within the directory!_

An example is shown below, the output of the command `ls -l` demonstrates the different permission types. Those permissions preceded by the `d` value, indicate a directory.

![Listing file and directory permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-159.png)

Listing file and directory permissions

Why then are there seemingly three sets of permission for each object? Granular control of permissions is achieved by dividing permissions into the sections (referenced as parties for the purpose of this tutorial) listed below.

*   **User (`u`):** The owner of a file or directory, highlighted in blue.
*   **Group (`g`):** Members of the group to which a file or directory belongs, highlighted in green.
*   **Other (`o`):** All additional users and groups not explicitly assigned, highlighted in red.

![Demonstrating the combined permissions for a file or directory.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-160.png)

Demonstrating the combined permissions for a file or directory

## Changing File Permissions via the chmod recursive Command

With the proper Linux permission understanding, read on to learn how to change file permissions. Permissions are modified via the `chmod` recursive command as shown in the below examples.

1\. First, check the current permissions with the `ls -l` command. Here, the _my\_dir/index.js_ file is shown.

![Checking the current permission of index.js.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-161.png)

Checking the current permission of _index.js._

2\. Run the `chmod` command, specifying the party, `a` (all), and the permissions, `rwx`, or read/write/execute. The full command follows: `chmod a=rwx index.js`.

![Changing index.js' permissions.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-162.png)

Changing _index.js’_ permissions.

3\. As you can see, running `chmod` recursive doesn’t return any output. To verify that permissions have changed run the command `ls -l` again.

![Verifying index.js permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-163.png)

Verifying _index.js_ permissions

### Setting File Permissions via Numeric Values

Remember the numbers associated with permissions such as read or write? Instead of specifying the character values, you may specify specific permissions via a number. By adding the values, you create a specific permission such as `6` which is a combination of write (`2`) and read (`4`) permissions.

In the example below, set permissions for the _main.py_ file via the command `chmod 664 main.py`. The numerical values break down as follows.

*   **User:** Read and Write (`6`).
*   **Group:** Read and Write (`6`).
*   **Other:** Read (`4`).

![Changing permissions for main.py.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-164.png)

Changing permissions for _main.py._

Once permissions are changed, verify the new permissions for the _main.py_ file with the command `ls -l`.

![Verifying permissions for main.py.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-165.png)

Verifying permissions for _main.py_

## Removing and Adding File Permissions

The non-numerical commands you have run so far used the assignment parameter (`=`) with `chmod` recursive, to set explicit permissions. Instead, you may remove (`-` ) or add (`+`) permissions to existing permission sets.

1\. First, list the existing permissions for the _README.md_ file via the command _`ls -l README.md`._

![Checking README.md current permissions.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-166.png)

Checking _README.md_ current permissions

2\. Next, add (`+`) execute (`x`) permissions to the user party (`u`), while removing (`-`) read (`r`) permissions from the other party (`o`) for _README.md_, with the following command `chmod u+x,o-r README.md`. Differing party permissions are separated by commas (`,`).

![Changing README.md permissions.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-167.png)

Changing _README.md_ permissions

3\. Run the `ls -l README.md` command to verify that permissions were modified.

![Checking README.md new permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-168.png)

Checking _README.md_ new permissions

## Recursively Changing File and Directory Permissions

Although you are making progress, you are only operating on one file at a time. What if you have a large number of files to change permissions for? Time to step up your game and learn to change permissions for multiple files.

One of the options to change multiple files is to run `chmod` recursive with the `-R` (recursive, and not the capital) option. The recursive option will change the permissions for all the files, including those under sub-directories, inside a given path.

1\. Consider the following command, `chmod -R a=r,u=rwx my_dir`. Most of the options you have already seen before.

This command will change the permissions for all files in the directory, _my\_dir_ and sub-directories, via the recursive option (`-R`). The files are set to readable (`r`) for all (`a`), with differing permission for the current user (`u`) set to full permissions (read, write, execute).

In the screenshot below, you see the resulting permissions after executing the command, which has no resulting output.

![Checking my\_dir files new permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-169.png)

Checking _my\_dir_ files new permissions

2\. Suppose you run the command, `chmod -R a=rwx my_dir`, on the same directory as before, _my\_dir._ Once again, you are changing all files in _my\_dir,_ and its subdirectories, to set give all (`a`) full permissions (read, write, execute). Here is the result of the command, as `chmod` recursive does not display output.

![Checking my\_dir files new permissions to confirm every part now has every permission.](https://adamtheautomator.com/wp-content/uploads/2021/12/image-170.png)

Checking _my\_dir_ files new permissions to confirm every part now has every permission

3\. How about the numeric method? As shown below, the recursive method also works with numeric permissions, `chmod -R 770 my_dir`. Here you are giving full permissions to the user and group, but no permissions to the other party.

![Recursively changing permissions with the numeric method](https://adamtheautomator.com/wp-content/uploads/2021/12/image-171.png)

Recursively changing permissions with the numeric method

4\. Run `ls -l` to check that _my\_dir_ files and sub-directories permissions are set with the numeric method.

![Checking the permissions set once again, this time with the numeric method](https://adamtheautomator.com/wp-content/uploads/2021/12/image-172.png)

Checking the permissions set once again, this time with the numeric method

## Defining File and Folder Behavior via Special Permissions

Special permissions allow for several additional privileges unique from the standard permission sets. There are three special permissions. Here is how these special permissions work and how you can add them to a file or directory.

### Setting the SUID (User + S) Permissions

Commonly noted as **SUID**, it is a special permission for the user. The **SUID** has a single function: a file with **SUID** always executes as the user who owns the file, regardless of who is executing the file.

For example, consider _index.js_. To give the additional **SUID** permission, run `chmod u+s index.js`.

Now, if you run `ls -l index.js`, you’ll find that the user has an **s** in their permissions instead of an x.

![Checking index.js new permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-173.png)

Checking _index.js_ new permissions

### Setting the SGID (Group + S) Permissions

Commonly noted as **SGID**, this special permission has two functions:

*   If set for a file, it allows the file to be executed as the **group** that owns the file, regardless of who is executing the file.
*   If set for a directory, any files created in the directory will have their **group** ownership set to that of the directory owner.

Practice on the _index.php_ file. To add the **SGID** permission to this file, run the following command: `chmod g+s index.php`.

Now, if you run `ls -l index.php`, you’ll find that the **group** has an **s** in their permissions.

![Checking index.php new permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-174.png)

Checking _index.php_ new permissions

Move on to a directory: _my\_dir_. You can add the **SGID** permission to this directory using the following command: `chmod g+s my_dir`. Any files created in this directory will now have their **group** ownership set to the directory owner. You can check the directory new permissions using `ls -ld my_dir` (the `d` parameter limits output to directories only).

![Checking my\_dir new permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-175.png)

Checking _my\_dir_ new permissions

### Changing the Sticky Bit Permission

The last special permission is also known as the “sticky bit.” This permission does not affect individual files. But, at the directory level, it restricts file deletion. Only the **owner** of a file can remove a file within that directory.

Add the sticky bit to the old familiar _my\_dir_ directory. To do that, run the command as follows: `chmod +t my_dir`.

> _Note that, to add the sticky bit, you do not indicate the **other** group(o) before the `+t`._

When you check _my\_dir_‘s new permissions, you will see a capital T in the **other** permissions, as shown in the screenshot below.

![Checking my\_dir new and special permissions](https://adamtheautomator.com/wp-content/uploads/2021/12/image-176.png)

Checking _my\_dir_ new and special permissions

## Conclusion

Congratulations! You covered a lot of topics on `chmod` recursive. You are now ready to tackle any pesky permission problems that arise with the almighty `chmod` tool. You even learned how to leverage the power of the recursive (`-R`) option.

How do you intend to implement `chmod` versatile functionality to your advantage next time you’ll need to manage file or directory permissions?

Related:[Your One and Only Linux Shell Scripting Tutorial](https://adamtheautomator.com/linux-shell-scripting-tutorial/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fchmod-recursive%2F&text=Manage%20Directory%20and%20File%20Permissions%20with%20chmod%20Recursive)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fchmod-recursive%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fchmod-recursive%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

### [Unleashing the Power of the Pipe Command in Linux](/pipe-command-in-linux/)

Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

![](https://adamtheautomator.com/wp-content/uploads/2022/07/How-to-Update-Ubuntu-IP-and-Hostname-via-Bash.jpg)

### [How to Update Ubuntu IP and Hostname via Bash](/change-linux-ip-hostname-bash-script/)

Discover and learn how to change a Linux IP and Hostname via a Bash script in this new tutorial by ATA Learning!

![](https://adamtheautomator.com/wp-content/uploads/2022/06/Behind-the-Scenes-of-Linux-Timezones-Dates-and-Time.jpg)

### [Effective Management Linux Timezones (Step by Step Tutorial)](/linux-timezones/)

Best practices for managing Linux timezones, dates, and time with practical examples for the IT administrator!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
