How to Change Permissions All Directories to 755 and Files to 644 Linux Ubuntu

How to Change Permissions All Directories to 755 and Files to 644 Linux Ubuntu

It is essential to secure directories, subdirectories and files in any system, To secure your file system and directories by changing the permissions of all directories, subdirectories, files and its content, Type “find . -type d -exec chmod 755 {} +” command on terminal window and press enter to change all directories permissions 777 to 755 and use “find . -type f -exec chmod 644 {} +” command to change all files permission 777 to 644 in linux ubuntu server.

Prerequisites to know the most common permissions used in Linux:

  • Read: that users can read in directories and files.
  • Write: that users can write in directories and files.
  • Execute: users can execute any program in directories and files.

To set permissions, there are three different groups of users, which are:

  • User: the owner of the file or directory
  • Group: A specific group with a name to allow permissions to a directory, subdirectory, and its contents.
  • Other: anyone else who is not the owner or a member of the group

Here are the steps to change all directory, subdirectories, files and it’s content permissions to 755 and files to 644 in Linux Ubuntu:

Step 1: Open your terminal

To start the terminal window or command prompt in Linux Ubuntu systems, you need to press Ctrl + Alt + T on the keyboard.

Step 2: Navigate to the directory

To change the permissions of any directory, subdirectory and its contents, you need to navigate to the terminal using the cd command:

cd directory

Suppose, if you want to change the permission of files and directories, subdirectories of /var/www/html directory from 777 to 755, 644, You have to use something like this command on a terminal window:

cd /var/www/html

Step 3: Change All Directories Permissions 777 to 755

To change the permissions of all directories from 777 to 755, type the command find . -type d -exec chmod 755 {} + On the Linux Ubuntu terminal window and press Enter, you would use the command like this:

find . -type d -exec chmod 755 {} +;

This command will find all directories in the current directory and set their permissions to 755. The -type d option specifies that you want to find directories only.

The -exec option tells the command to execute the chmod command on each directory that it finds. The {} symbol represents the directory that the command finds, and the ; symbol terminates the command.

Step 4: Change All Files Permissions 777 to 644

To change the permissions of all files from 777 to 755 in directory tree, use the command find . -type f -exec chmod 644 {} + On the Linux Ubuntu terminal window and press Enter, you would use the command like this:

find . -type f -exec chmod 644 {} +

This command will find all files in the current directory and set their permissions to 644. The -type f option specifies that you want to find files only.

The -exec option tells the command to execute the chmod command on each file that it finds. The {} symbol represents the file that the command finds, and the ; symbol terminates the command.

Step 5: Verify the permissions

After executing these commands, it’s important to verify that the permissions have been changed correctly, This command will display to you the permissions related to your directories and files on the terminal window:

ls -l

You should see a list of all files and directories, along with their permissions. Directories should have permissions of ‘drwxr-xr-x’ (755), and files should have permissions of ‘-rw-r–r–‘ (644). If you see anything else, you may need to run the commands again.

Step 6: Recursive Change Permissions All Directories to 755 and Files to 644 (Optional)

To change recursively permissions 777 of all folders, subfolders, files and it’s contents to 755 and 644, you have to use the -r option with the chmod command, you can use it like this:

chmod -R 755 /path/to/parent/directory
chmod -R 644 /path/to/parent/directory

Here is the video guide on how to change permissions for all directories to 755 and all files to 644 in Linux ubuntu terminal window:

Conclusion

That’s it, You have learned how to change the permissions of a directory, subdirectories, files, and its contents from 777 to 755 and 644 using chmod command on the Linux Ubuntu terminal window.

Recommended Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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