I have to copy contents of some code from one folder called aim-db-dir to another called aim-db-dir_nosvn. aim-db-dir contains .svn folders in all the directories (and subdirectories) and these .svn folders contain some folders and files which I am not concerned with. I want to copy everything in the directories and subdirectories under aim-db-dir except the .svn folders and its contents.

So my question is how do I do this. I read about rsync but am not sure we can exclude directory and file patterns. Also I tried to do using find and cp but I am missing on something.

The command I am trying is something like (doesn't work)-

find aim-db-dir/* -not -name ".svn" | sed -n 's|^aim-db-dir/||p' -exec cp -R "{}" "aim-db-dir_nosvn/{}" \;

I also thought of using xargs but I never used so not sure if it can be made use of. Multiple solutions are appreciated!

  • The gnu tar program has a --exclude-vcs option, which will avoid all .svn directories. You can pipe tar to/from stdout/stdin, and use -C to get to the correct starting directory.
    – KevinO
    Jun 8, 2017 at 4:57

1 Answer 1


With GNU find and GNU cpio:

find /path/to/aim-db-dir -name .svn -prune -o -print0 | cpio -padmv0 /path/to/aim-db-dir_nosvn

With rsync:

rsync -av -exclude=.svn /path/to/aim-db-dir/ /path/to/aim-db-dir_nosvn

The trailing slash in the /path/to/aim-db-dir/ is important, without it a directory named aim-db-dir is created in aim-db-dir_nosvn.

With GNU tar:

tar cpf - --exclude-vcs -C /path/to/aim-db-dir . | tar xvpf - -C /path/to/aim-db-dir_nosvn

There is a limit on the maximum length of the paths of the files you can copy with tar, coming from a limitation in the underlying PAX format.

You must log in to answer this question.

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