I am trying to write a simple bash script that will copy the entire contents of a folder including hidden files and folders into another folder, but I want to exclude certain specific folders. How could I achieve this?
rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination
Note that using
source/ are different. A trailing slash means to copy the contents of the folder
destination. Without the trailing slash, it means copy the folder
Alternatively, if you have lots of directories (or files) to exclude, you can use
FILE is the name of a file containing files or directories to exclude.
--exclude may also contain wildcards, such as
Use tar along with a pipe.
cd /source_directory tar cf - --exclude=dir_to_exclude . | (cd /destination && tar xvf - )
You can even use this technique across ssh.