I would like to change permissions of a folder and all its sub folders and files in one step (command) in Linux.
I have already tried the below command but it works
There are two answers of finding files and applying chmod
to them. First one is find
the file and apply chmod
as it finds (as suggested by @WombleGoneBad).
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
Second solution is to generate list of all files with find
command and supply this list to the chmod
command (as suggested by @lamgesh).
chmod 755 $(find /path/to/base/dir -type d)
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)
otherwise