Copy folder recursively, excluding some folders - Stack Overflow

Copy folder recursively, excluding some folders - Stack Overflow

Tuesday, August 25, 2015

4:23 PM

Use rsync:

rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination

Note that using source and source/ are different. A trailing slash means to copy the contents of the folder source into destination. Without the trailing slash, it means copy the folder source into destination.

Alternatively, if you have lots of directories (or files) to exclude, you can use --exclude-from=FILE, where FILE is the name of a file containing files or directories to exclude.

--exclude may also contain wildcards, such as --exclude=*/.svn*

want to recursively copy an entire structure and only keep a certain type of files then you can also use

rsync: rsync -rav --include=*/ --include=".txt" --exclude= test/ mytest

This will take all .txt files from source directory and copy them to destination directory with the structure intact.

From <http://stackoverflow.com/questions/2193584/copy-folder-recursively-excluding-some-folders>

Inserted from <http://stackoverflow.com/questions/2193584/copy-folder-recursively-excluding-some-folders>

Created with Microsoft OneNote 2013.


Copy folder recursively, excluding some folders - Stack Overflow

Copy folder recursively, excluding some folders - Stack Overflow

Tuesday, August 25, 2015

4:23 PM

Use rsync:

rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination

Note that using source and source/ are different. A trailing slash means to copy the contents of the folder source into destination. Without the trailing slash, it means copy the folder source into destination.

Alternatively, if you have lots of directories (or files) to exclude, you can use --exclude-from=FILE, where FILE is the name of a file containing files or directories to exclude.

--exclude may also contain wildcards, such as --exclude=*/.svn*

want to recursively copy an entire structure and only keep a certain type of files then you can also use

rsync: rsync -rav --include=*/ --include=".txt" --exclude= test/ mytest

This will take all .txt files from source directory and copy them to destination directory with the structure intact.

From <http://stackoverflow.com/questions/2193584/copy-folder-recursively-excluding-some-folders>

Inserted from <http://stackoverflow.com/questions/2193584/copy-folder-recursively-excluding-some-folders>

Created with Microsoft OneNote 2016.