linux - [Solved-15 Solutions] How to set chmod for a folder and all of its subfolders and files in Linux Ubuntu Terminal ? - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
How to set chmod for a folder and all of its subfolders and files in Linux Ubuntu Terminal ?
Linux - Solution 1:
chmod -R 755 will set this as permissions to all files and folders in the tree. You can use the find command. For example:
To change all the directories to 755 (drwxr-xr-x):
To change all the files to 644 (-rw-r--r--):
Linux - Solution 2:
Check the -R option
So in this case:
Linux - Solution 3:
If you want to set permissions on all files to a+r, and all directories to a+x, and do that recursively through the complete subdirectory tree, use:
The X (that is capital X, not small x!) is ignored for files (unless they are executable for someone already) but is used for directories.
Linux - Solution 4:
You can use -R with chmod for recursive traversal of all files and subfolders.
You might need sudo as it depends on LAMP being installed by the current user or another one:
Linux - Solution 5:
To set to all subfolders (recursively) use -R
Linux - Solution 6:
chmod 755 -R /opt/lampp/htdocs will recursively set the permissions. There's no way to set the permissions for files automatically in only this directory that are created after you set the permissions, but you could change your system-wide default file permissions with by setting umask 022.
Linux - Solution 7:
Linux - Solution 8:
Here's another way to set directories to 775 and files to 664.
It may look long, but it's pretty cool for three reasons:
- Scans through the file system only once rather than twice.
- Provides better control over how files are handled vs. how directories are handled. This is useful when working with special modes such as the sticky bit, which you probably want to apply to directories but not files.
- Uses a technique straight out of the man pages (see below).
Linux - Solution 9:
Use this:
It can really hurt you if you change the permissions of the wrong files/folders.
Linux - Solution 10:
The recursive command is:
- -R: change every sub folder including the current folder
Linux - Solution 11:
Ensure that appropriate files and directories are chmod-ed/permissions for those are appropriate. For all directories you want
And for all the images, JavaScript, CSS, HTML...well, you shouldn't execute them. So use
But for all the logic code (for instance PHP code), you should set permissions such that the user can't see that code:
Linux - Solution 12:
Linux - Solution 13:
For Mac OS X 10.7 (Lion), it is:
Linux - Solution 14:
In Terminal go to file manager. example: sudo nemo. Go /opt/ then click Properties → Permission. and then Other. Finally, change to create and delete and file acess to read and write and click on button apply.