chmod: How to recursively add execute permissions only to files which already have execute permission
25,380
Solution 1
Use find
:
find . -perm /u+x -execdir chmod a+x {} \;
Solution 2
You can use find to get all those files:
find . -type f -perm -o+rx -print0 | xargs -0 chmod a+x
Update: add -print0 to preserve space in filenames
Author by
Clinton
Updated on July 20, 2022Comments
-
Clinton almost 2 years
I noticed:
chmod -R a+x
adds execute permissions to all files, not just those who are currently executable.Is there a way to add execute permissions only to those files who already have an execute set for the user permission?
-
Mat almost 13 yearsDon't do it that way, it screws up with spaces in the filenames. If you want to pipe to xargs, use the
-print0
find option and the-0
xargs option. -
jw013 almost 13 yearsUse
-execdir
; it's safer than-exec
. Also sincechmod
accepts multiple files in one command line,+
instead of\;
may have better performance. -
codeling over 10 yearsthanks for mentioning the
+
mode! The-execdir
instead of-exec
squashes the gained performance benefit again, though; and since find delivers full file paths anyway, does it matter much? the fastest command for me was... -exec chmod <mode> {} +