Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

wget's timestamping functionality ensures it only downloads files that have changed. I'm looking for a linux command-line tool that will recursively compare a directories contents with a saved version (from the last time it ran), and execute an arbitary shell command on any new or updated files. Basically:

run-on-updated --directory /path/to/my/dir --last-results ~/.lastrun --exec "echo {}"

I could even imagine this as an extension of the 'find' command. Does such a tool exist?

share|improve this question
~/.lastrun is just a file, right? Not a copy of the complete directory? In the latter case you could start with rsync -v --dry-run /path/to/my/dir ~/.lastrun – mpy Mar 2 '13 at 23:21
Ideally it should be just the file metadata (e.g. path, size, last-modified) rather than a copy of the directory as that'd be too large. rsync definitely has this timestamping functionality though - but I hope to find it as a standalone tool (the unix philosophy?) – Nicholas White Mar 2 '13 at 23:33
up vote 3 down vote accepted

An attempt to answer the question -- probably with lots of room for improvement:

tar -cv -f /dev/null -g ~/.lastrun /path/to/my/dir | grep -ve '/$' | xargs -I{} echo '{}'

Note for the tar command: "The option ‘-g’ instructs tar to operate on an incremental archive with additional metadata stored in a standalone file, called a snapshot file. The purpose of this file is to help determine which files have been changed, added or deleted since the last backup, so that the next incremental backup will contain only modified files." (Quote from doc)

The grep command excludes directory names (ending with /) which tar always outputs, and finally xargswill run the desired command on the files.

share|improve this answer
This works! It updates the ~/.lastrun file in-place which is useful too. – Nicholas White Mar 3 '13 at 1:29
Glad it works for you. Please take care if there are some file names with whitespaces (I was too tired yesterday to think of that ;) You'll be saver when using xargs -I{} echo '{}' -- I edited my answer accordingly. – mpy Mar 3 '13 at 10:55

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.