Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do i need copy all files except a couple of directories from one directory to another. for eg:

cp -R test /www/test2 would copy all

But i want to exclude 2 folders called log and logs.

I tried something like:

find ~test -not -name logs,log |  cp -R test /www/test2 

But can you help me with the syntax?

share|improve this question

migrated from stackoverflow.com Oct 25 '12 at 9:31

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

3 Answers 3

up vote 8 down vote accepted

Use rsync:

rsync -a --exclude=logs --exclude=log from/ to/
share|improve this answer
the rynsc kinda worked cool for me! –  Micheal Oct 25 '12 at 18:14
rsync is now my new friend :) Thanks, the explanation is neat –  Aleks May 26 '14 at 14:56

I think you're looking for something like:

find dir -type d ! \( -name 'log' -o -name 'logs' \) | xargs -I{} cp -R {} /www/test2/{}
share|improve this answer
@sputnick see my changes. Feel free to offer up the emacs regex for this if you happen to know it. –  Tim Pote Oct 24 '12 at 22:38

If using :

shopt -s extglob
cp -R test/!(log|logs) /www/test2

See http://wiki.bash-hackers.org/syntax/pattern

share|improve this answer
What happens when the structure is like so: test/someotherdir/logs? OP never said log and logs was the second-highest directory. –  Tim Pote Oct 24 '12 at 22:43
If you re-read OP command find ~test -not -name logs,log log & logs should be a sub-dir. –  StardustOne Oct 24 '12 at 22:53
find looks recursively through all sub-directories. File globbing doesn't. For your answer to work, log and logs would have to be immediate sub-directories of test. –  Tim Pote Oct 25 '12 at 0:55

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.