Main Content

Finding what has changed - Linux / Unix

Archive - Originally posted on "The Horse's Mouth" - 2010-02-17 08:00:56 - Graham Ellis

If you want to find out what has changed in a file, use the diff command. And if you want to find out what has changed across a whole directory structure, use diff -r

If I want to compare a backup with my current system - to see what has been altered (perhaps when something has gone wrong and I want to know what it might be), then one of the tools I might use is diff:

[trainee@easterton ooerr]$ diff -r trainee.bak trainee
Only in trainee.bak/a654: 6_web.xml
diff -r trainee.bak/y205/gui1.py trainee/y205/gui1.py
7c7
< widget = Label(None, text="Hello World")
---
> widget = Label(Lots, text="Hello World")
[trainee@easterton ooerr]$


And that shows me that since I took the backup, a file called 6_web.xml has been deleted and the 7th line of a file called gui1.py has been altered.

Another way of finding recent changes is the find command, which can be used for many other file system searches too. Here's how I would use it to find all files and directories that have been altered in the last day in the same directory that I was checking above:

[trainee@easterton ooerr]$ find trainee -mtime -1 -print
trainee/a654
trainee/y205
trainee/y205/gui1.py
[trainee@easterton ooerr]$