Trying to perform a recursive chmod on all the .sh files in a directory to make them executable

  • Look into find and maybe xargs.
    – fkraiem
    Mar 4, 2017 at 2:37

2 Answers 2


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 {} \;


  1. -type f: Normal files only (skip directories, symlinks, named pipes and sockets, and the special files found in /dev)
  2. -iname: Ignore case in the name
  3. "*.sh": Globbing, telling the find command to search for files with ".sh" extension
  4. -exec chmod +x {}: This tells the find command to carry out a chmod command on each found file. Making each executable
  5. \;: Indicating end of command
  • 3
    I 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 3, 2021 at 9:31
  • Do you mean terminating exec with \; vs \+? Jun 29, 2021 at 19:16
chmod u+x /dir_of_interest/**/*.sh

Credit to: https://www.commandlinefu.com/commands/view/11936/recursive-chmod-all-.sh-files-within-the-current-directory

  • You need shopt -s globstar in bash for that to work.
    – muru
    May 5, 2021 at 16:31
  • 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, 2022 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .