Trying to perform a recursive chmod on all the .sh files in a directory to make them executable
Asked
Active
Viewed 6.0k times
41
-
Look into `find` and maybe `xargs`. – fkraiem Mar 04 '17 at 02:37
2 Answers
58
To make this possible you can use the find command and search for all files with a .sh extension and then run the chmod command on each one found:
find /directory/of/interest/ -type f -iname "*.sh" -exec chmod +x {} \;
Information:
-type f: Normal files only (skip directories, symlinks, named pipes and sockets, and the special files found in /dev)-iname: Ignore case in the name"*.sh": Globbing, telling thefindcommand to search for files with ".sh" extension-exec chmod +x {}: This tells thefindcommand to carry out achmodcommand on each found file. Making each executable\;: Indicating end of command
Eliah Kagan
- 116,445
- 54
- 318
- 493
George Udosen
- 35,970
- 13
- 99
- 121
-
3I think that you could end your find command with `+` to minimize the number of execution (see the difference between terminating exec with `\;` vs `+`). – ncenerar May 03 '21 at 09:31
-
2
chmod u+x /dir_of_interest/**/*.sh
rainabba
- 257
- 2
- 5
-
-
Works. But if there are too many files to update `unable to execute /usr/bin/chmod: Argument list too long` error occurs. Then we can use the answer by @George Udosen. – Wenuka Nov 16 '22 at 08:23