Ubuntu Technical

Ubuntu technical problems and solutions reference, a modern cookbook.

Sync directories excluding file types

I have recently needed to find a solution to moving the content of a directory from one folder into another, but excluding certain file types. After digging through the documentation I have found the rsync command.
Short extract from it’s man pages:

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

So, here is the script to copy files from one place to another ignoring certain file types (in this example I exclude .avi files):

rsync /source/folder -av --exclude='*.avi' /destination/folder

The -v option is for verbose, so that we can see in the output what’s being synced.
Enjoy.



Flattr this

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: