Linux: Finding Newer Files [OR How To Create A Patch File]

The linux `find` command is very powerful, it has tonnes of switches and options that I’m not terribly familiar with. Even though I’ve been a LAMP developer for over 5 years, I don’t work on the command-line too often. Yesterday I ran into a problem that I had never tried to resolve before. I was working on a large project on a development server and I had some updates I wanted to push to the production server, but I had lost track of which files I had updated. I dug through the find manual for a few minutes and discovered the `-newer` flag, from man “File was modified more recently than file.” With this flag you can generate a list of files that are newer than a given file. If I set file to a file I knew had been updated before my last set of changes, I could pull a list of patch files.

find /path/to/project/ -newer /path/to/project/last-archive.tgz

After some more digging and trial and error I found the proper syntax for rolling up all these files into a nice little patch archive:

tar -czvf patch-20070321.tar `find /path/to/project/ -newer /path/to/project/last-archive.tgz -print`

Leave a Reply

Your email address will not be published. Required fields are marked *