Help me !1


How do I set chmod for a folder and all of its subfolders and files in Linux Ubuntu Terminal?
Also, in the future, if I create a new folder or file inside htdocs, how can the permissions of that automatically be set to 755?


Read the documentation: have you tried searching for chmod on DreamHost knowledge base? this is the first result:

As for default file permissions, those should be created ‘correctly’ in DreamHost systems. In any case to establish the permissions for new files in a folder you need to set the umask. There are lots of good tutorials online that will explain the concepts behind Linux/Unix file permissions. This one for example:


You would be able to chmod a folder/directory and its subfolder/directories with chmod -R $permission $directory where $permission would be the value like 644 or 755 and $directory would be the directory that you would like to change. By doing that you’ll end up with files/directories as the same permission. The -R flag in chmod means that it will recursively change the permissions for files/subdirectories it finds in the directory you specify.

Ideally in a web hosting environment you’d want to have directories set as 755 and folders set to 644.
You would be able to target specifically directories with this command find $directory/ -type d -exec chmod -v 0755 '{}' \; and files with find $directory/ -type f -exec chmod -v 0644 '{}' \; again where $directory is the folder that you want to change.

eg. find /home/user/ -type d -exec chmod -v 0755 '{}' \; would change all the directories inside of and set them to 755.

eg2. find /home/user/ -type f -exec chmod -v 0644 '{}' \; would change all the files inside of and set them to 644.

To set your linux user to automatically create a directory/file of a specific permission you would need to edit your shells setting file to change the umask value. More information on that here
You will also want to make sure to make a backup of the shell settings file before you modify it, and have access to another shell user to make changes for you in case you have any issues and render the shell user unusable.

Another way to create a directory and set the permissions in one step would be to use mkdir -m 755 $directory where $directory again is the directory that you specify, This would create the directory with the permission of 755, or any other permission that you set.

Hope this helps!