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

I want to write a .sh script to setup some folder permissions, but was wonder if I can run something like:

chown -644 ./one;/two;/three

to chown a list of folders, rather than calling chown multiple times.

Also, would there be a way to chown a list of files, and exclude some others, like for example:

chown -R -664 ./*;!./cache

I hope my pseudo command lines make sense.

share|improve this question
up vote 7 down vote accepted

Almost all Unix tools accept a list of files as non-option arguments. As usual, the different arguments have to be separated by space:

chown 644 one two three

In your second example, if you're using Bash, a simple

chown -R 644 !(cache)

will be enough.

This approach requires extended pattern matching. If it's disabled, you can enable it with

shopt -s extglob

See: Bash Reference Manual # Pattern Matching

share|improve this answer

Make a list of filenames in mod-these.txt and then run:

chmod g+w `cat mod-these.txt`

or use the method described by others here:

chown 644 one two three

or go to town with the first option but manipulate each line in the file (in this example: replace " /" (WITH whitespace before) by " ./"):

chmod g+w `sed 's/ \// .\//' update-writable.txt` 
share|improve this answer

regex for the win!

using find is the best way I can think of outside of using the regex that may already exist in your particular shell or within the app you are using itself. first, I tried:

touch one&touch two &touch three&find -name "one|two|three" -exec chown -644 {} \;

But, you'll find that the pipe doesn't work in this case. Another sad thing to learning chmod,chown,chgrp,et. al. doesn't support multi-file/regex selection/exclusion itself...
The solution I found:

find \( -name one -o -name two -o -name three \) -exec chown -644 {} \;

so, not so much regex for the win, but at least we have a way to inject a list of files into the args of a program in a one liner.

you'll note that you need to escape the () meta-characters, and the addition of the -o parameter for each additional name...

other links and content from me which might interest you along your travels:
Various tidbits - notes from korn bourne and friends. - Dave Horner's Website


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.