Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to find all the files under a directory which are within 24 hours then rsync those files with another server.

There are some old files that I do not want to transfer, however if those old files are updated then I do.

I was thinking of writing a script with: find and the -ctime parameter and redirect that output to a file, but I don't know how to get rsync to effectively use that, or if there is a better way to transfer a set of files which have changed in the last 24 hours.

This process needs to be run very frequently, so am not looking for something too inefficient. (such as using ftp and sending everything each time).

Any ideas appreciated.

share|improve this question
I've updated my answer again. It looks like --include-from is not enough, as the default behavior is to include everything. You need to explicitly tell it to --exclude everything in order for it to act like a white list. – SiegeX Jan 28 '12 at 2:25
up vote 7 down vote accepted

Try this:

cd /some/dir && rsync -av --files-from=<(find . -mtime 0 -printf "%p\n") <other stuff>

It uses Process Substitution <( ) to replace the find command with a named fifo and gives that fifo's name to rsync to read as what to include in the sync.


In light of Kyle's answer, it definitely appears that --files-from is more appropriate than --include-from; although both will work. Answer updated

share|improve this answer
rsync is a one way, unidirectional sync system. Use unison if two-way, bidirectional sync system is needed. – Nikhil Mulley Jan 28 '12 at 12:03

cd $LOCALDIR || { echo cd failed 1>&2; exit 1; }

trap 'rm -f $thefiles' 0

find . -type f -ctime -$changetime -print > $thefiles
rsync -v -n --archive --files-from=$thefiles . $REMOTEHOST:$REMOTEDIR

This script runs find in $LOCALDIR, dumping the results into a file, then tells rsync to use the file contents as a list of files to transfer to the directory $REMOTEDIR on the host $REMOTEHOST. The script chdir's into $LOCALDIR because the rsync command needs relative paths, not absolute ones. I left -v -n in the rsync args so you can see what this does without copying anything; remove -n when you're satisfied the script does what you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.