How to Recursively Change File Permissions in Ubuntu Using chmod

Why Use Recursive Permissions?

When working with web servers (like Apache or Nginx) or managing large project folders in Ubuntu Linux, you will frequently need to adjust file permissions to ensure applications have the correct access rights to read, write, or execute files. The standard chmod command changes the permissions of a single target file. However, if you just uploaded a WordPress directory containing thousands of files and subdirectories, manually running chmod on each one is impossible. You need to use a recursive command to automatically apply your new permission rules to the parent directory and every single file nested inside it simultaneously.

Using the Recursive Flag

The chmod command uses a very simple flag to trigger recursive behavior: a capital -R. (It is crucial that you use a capital R, as Linux commands are strictly case-sensitive).

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. The basic syntax for the command is: sudo chmod -R [permissions] [directory_path].

Practical Examples

Here are two of the most common scenarios where you would use recursive permissions.

Example 1: Granting Full Access to a Project Folder

If you are setting up a local development environment and want to grant read, write, and execute permissions (777) to yourself and all other users for a specific folder and all its contents, you would run:

  1. sudo chmod -R 777 /var/www/html/my_project
  2. Press Enter and provide your administrator password. The system will instantly update every file inside that folder.

Warning: Never use 777 permissions on a live, public-facing web server, as it is a massive security risk.

Example 2: Setting Standard Web Server Permissions

A much safer and more common task is setting standard web directory permissions, where the owner has full read/write access (755), but the public can only read and execute.

  1. sudo chmod -R 755 /var/www/html/public_site
  2. Press Enter.

By mastering the -R flag, you can safely manage massive directory trees with a single keystroke, eliminating hours of tedious command-line administration.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.