TL;DR:
ls [source] | rsync -a --exclude-from=- [source] [dest]
I’ve recently been working on setting up a backup solution for my various computers. One of the things I wanted to do was backup only my program settings. In unix-like operating systems, these are usually stored in the user’s home directory, with a . in the beginning of the filename. This denotes that the file is hidden by default.
Rsync is a utility that is used to copy files from a source to a destination, optionally over a network. It is great for backups since it checks the contents of the files on both sides, and only sends the (parts of) the files that have changed.
Rsync can be a bit cumbersome to use, and I searched google for a while and even asked in their IRC channel for help. I couldn’t figure out how to make rsync select only my dotdirs. I figured it out today.
The command is:
ls [source] | rsync -a --exclude-from=- [source] [dest]
How it works: by default, ls only shows non-hidden files. So, the command ls builds a list of files and directories that are not hidden – a list of everything I don’t want. I pipe that to rsync -a (a is for archive). –exclude-from usually operates on files, but when you give it a – as a filename, it reads from stdin instead. In this case, stdin is the listing of stuff that I don’t want, piped from ls. Works perfectly.
Comments (1)RSS feed for comments on this post. TrackBack URL
This is a great solution, very clean and clever! Nice. Thanks.
Comment by ponk — March 29, 2010 @ 10:36 am