How can I set different permissions for files and folders separately?
Solution 1:
Use find
:
find ./ -type f -maxdepth 1 -exec chmod 644 {} \;
find ./ -type d -maxdepth 1 -exec chmod 755 {} \;
-
-type f
: Files -
-type d
: Directories -
-maxdepth 1
: first level (to avoid default recursive behavior) -
-exec
: execute command on with argument from result -
{}
will be replaced with a line from results. try:find ./ -type d -maxdepth 1 -exec echo hi{}low \;
This useful for commands which have different arguments order like
ln
:ln -s {} ./otherfolder/{}
or
cp
cp {} ./otherfolder/
-
\;
to to tell-exec
is the end of command because you can add otherfind
options after-exec
(so they will not mix up). try:find ./ -type d -maxdepth 1 -exec echo
Reference: man find