Find, you are a dirty mistress
In my latest task at work, I have to write a script to take the most recent file from a particular directory changed within the last 240 minutes and copy it to a particular dated directory, in YYYYMMDDHHMM style.
After some digging in the ‘find’ manual page and bothering a co-worker I present:
find $directory -mmin -240 -name ‘foobarstring’ -printf “%p\n%CY%Cm%Cd%CH%CM\n”
This prints out on two successive lines:
$(dated string in the date format above)
The hardest part was getting the printf syntax right. When it works, it just works.