Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to change all files/directories permission except one single directory in a single Linux command line command?

share|improve this question

migrated from Sep 17 '12 at 20:05

This question came from our site for professional and enthusiast programmers.

grep -v "directory to exclude" – user1655481 Sep 17 '12 at 18:03
up vote 1 down vote accepted

Assuming that you wish to set the permission bit 755 recursively for the contents of the folders in your current working directory, apart from the contents of the folder called "nameOfFolderToBeExcluded":

 chmod 755 -R $(ls | awk '{if($1 != "nameOfFolderToBeExcluded"){ print $1 }}')
share|improve this answer

What shell?

If you're running bash (likely if you're on Linux), you can check out extglob, which gives you more options for globbing, including the "negative glob" !()

shopt -s extglob
chmod 774 !(file-to-ignore)
share|improve this answer

You can use find to search for all the files that does not match the given filename and exec a command on all such files found as:

Assuming you need to exclude directory test and give file permissions 755 to all other files and directores. This would be excecuted from the top of the tree.

find ! -name test -exec chmod 755 {} \;


mtk@mtk4-laptop:$ touch a1.txt a2.txt a3.txt test
mtk@mtk4-laptop:$ ls -lrt
total 0
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 test
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 a3.txt
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 a2.txt
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 a1.txt
mtk@mtk4-laptop:$ find ! -name test -exec chmod 777 {} \;
mtk@mtk4-laptop:$ ls -lrt
total 0
-rw-rw-r-- 1 mtk mtk 0 Sep 17 23:55 test
-rwxrwxrwx 1 mtk mtk 0 Sep 17 23:55 a3.txt*
-rwxrwxrwx 1 mtk mtk 0 Sep 17 23:55 a2.txt*
-rwxrwxrwx 1 mtk mtk 0 Sep 17 23:55 a1.txt*

The file permissions for file test remained unchanged. Same is applicable for directories.

share|improve this answer

Using find more simply like this:

find <from_where_to_change> -not -path "*/<excluded_dir_name>*" [-and -not -path "*/<another_excluded_dir_if_you_want>*"] -exec chown <user>[:<group>] {} \;

In my case it was:

find /data/project -not -path "*/.svn*" -exec chown :www-data {} \;

This way I changed group on folder /data/project recursively, except all folders ".svn" recursively.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.