How to change permissions for directories and files recursively

Oct 25, 2021 · 1 min read · Post a comment

Getting to know how to fix the directories and files permissions recursively, with a quick and easy method is always a good point. The crux of this tutorial is to understand how you can separately change the directories permissions and files as well. Let’s go to the solution.


  • Linux bash environment


Step 1. Let’s say we want to fix only the directories to 755 under /var/www/html.

find /var/www/html -type d -exec chmod 755 {} \;

Step 2. To do the same fix only for the files (644) under the same path /var/www/html.

find /var/www/html -type f -exec chmod 644 {} \;

Step 3. Explanation of the find command:

  • chmod 755 {}: Assign 755 permissions for each directory under the specified path.
  • chmod 644 {}: Assign 644 permissions for each file under the specified path.
  • \;: Escape the semicolon instead of being executed by the shell.
  • type: Whether it’s a file (f) or directory (d).


The path is the only section that may vary depending on your case, the rest of the command is just a simple copy-paste job that will quickly help you to fix the permissions. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.