Is there a way to set chmod 755
for /opt/lampp/htdocs
and all of its content including subfolders and files?
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
?
This works, but only for this folder:
chmod 775 /opt/lampp/htdocs
You can use
-R
withchmod
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:
There are two answers of finding files and applying
chmod
to them. First one isfind
the file and applychmod
as it finds (as suggested by @WombleGoneBad).Second solution is to generate list of all files with
find
command and supply this list to thechmod
command (as suggested by @lamgesh).Both of these versions work nice as long as the number of files returned by the
find
command is small. The second solution looks great to eye and more readable than the first one. If there are large number of files, the second solution returns error :Argument list too long.
So my suggestion is
chmod -R 755 /opt/lampp/htdocs
if you want to change permissions of all files and directories at once.find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
if the number of files you are using is very large. The-type x
option searches for specific type of file only, where d is used for finding directory, f for file and l for link.chmod 755 $(find /path/to/base/dir -type d)
otherwiseYou might want to consider this answer given by nik on superuser and use "one chmod" for all files/folders like this:
chmod -R 755 directory_name
works, but how would you keep new files to 755 also? The file's permissions becomes the default permission.If you want to set permissions on all files to
a+r
, and all directories toa+x
, and do that recursively through the complete subdirectory tree, use:The
X
(that is capitalX
, not smallx
!) is ignored for files (unless they are executable for someone already) but is used for directories.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 settingumask 022
.