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 have a Debian powered NAS server (ReadyNAS) with a deep file hierarchy. I'd like to get notified daily about what has changed in some of its directories and their subdirectories.

So if someone accidentally deletes a file during the day, I'd get notified about it at night by email (which would contain summary of all changes) and restore the file from backup in the morning of the next day.

At first I wanted to write a PHP CL or Python script which would recursively scan the directories, but then I thought that perhaps there is some neat unix tool that does it better. Something like dircmp :)

How would you do it?


share|improve this question

Run tripwire as a nightly job.

Alternatively, put the whole system under version control. Run the version control tool's diff command to see changes and its revert command (however it's called) to revert any changes in the local copy. Note that most version control systems handle file contents but require extra work for meta data such as permissions.

Alternatively, use a storage system with some form of snapshotting support, such as LVM or virtual machines.

Alternatively, why don't use prevent all changes in the first place?

share|improve this answer
"put the whole system under version control" , what is it ? – Hanan N. Dec 1 '11 at 4:18

You could write a script that does something like this (untested, sorry) and put it in a crontab:


# whom to mail

# what directory to look in

# make the directory safer to embed in filenames
dirname=$(echo $dir | tr "/" "-" | tail -c +2)

# today's date, add hours & minutes if you want to run it more often
today=$(date +"%Y%m%d")

# yesterday's date
yesterday=$(date -d -1day +"%Y%m%d")

# filenames

# the business. Use find -printf if you want to capture additional metadata.
find $dir |sort |bzip2 > $todayfile

if [ -r $yesterdayfile ]; then
    bzdiff $yesterdayfile $todayfile | mail $mailto -s "Directory differences for $dir from $yesterday to $today" 
    echo "No file listing from $yesterday, can't produce report | mail $mailto -s "Unable to report directory differences for $dir, no report from $yesterday"

Or you could just use my product which makes this kind of thing really easy. :)

[no such product anymore, sorry]

share|improve this answer

With BTRFS you can mount a live snapshot filesystem in which all changed files are 'stored'.

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.