I am having to do chmod -R 755 some_dir where 'some_dir' contains '.git' folders. Is there any way I can exclude hidden files and folder when doing recursive chmod?

Note: chmoding .git folder is throwing the following error

some_dir/.git/objects/pack/pack-dd149b11c4e5d205e3022836d49a972684de8daa.idx': Operation not permitted

I don't really need to chmod .git folders but unfortunately I can't remove them also in my case.

3 Answers 3


Not with chmod alone. You'll need to use find:

find some_dir -name '.?*' -prune -o -exec chmod 755 {} +

Or with zsh (or ksh93 -G, or with tcsh after set globstar) globbing:

chmod 755 -- some_dir some_dir/**/*

(you can also do that with fish or bash -O globstar, but beware that bash versions prior to 4.3 and fish follow symlinks when descending directories. It was partly fixed in bash 4.3 in that you'd still get the files in symlinks to directories but not anymore in subdirs of those as in 4.2, and fully fixed in 5.0)

Are you sure you want to make all the files executable though?

  • I am modifying an existing script and till I could figure out why they are doing the chmod in the first place this will have to do :)
    – Krishnaraj
    Oct 24, 2013 at 9:47

Tried with Below command and it worked fine

find path| sed -n '/^\.\/\./!p'|awk '{print "chmod -R" " "  "755" " " $1}'|sh
find /Your/Folder -type d -regextype posix-extended -regex ^[^\.].*$ -exec chmod -R 755 {}

^[^\.] : will exclude all file names beginning with a dot.

  • [ and * need quoted for the shell, . doesn't. That will always match anyway since -regex matches the whole path, not the file name, and the whole path starts with /Your/Folder, not a dot. Oct 24, 2013 at 10:04

You must log in to answer this question.

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