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?



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?

  • "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]


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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