Take all the file structure but these directories

cpfile-copy

I want to copy an entire file structure (with thousands of files and hundreds of directories), it's a hierarchy of directories and there are those node_modules directory that I want to exclude from the copying process.

Is there a Unix command to copy from a directory and all of its files and sub-directories recursively with an option to say don't include the directories with the name <name> ?

Something like :

cp root/ rootCopy/ --except node_modules

?

If not, is there a simple way to do that from the command line without writing a bash or something ?

Best Answer

You can try with rsync or tar command .

See this or this post.

From rsync man page

    --exclude=PATTERN       exclude files matching PATTERN
    --exclude-from=FILE     read exclude patterns from FILE

rsync -avz --exclude 'dir*' source/ destination/
Related Question