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 “%pn%CY%Cm%Cd%CH%CMn”
This prints out on two successive lines:
$(filename)
$(dated string in the date format above)
The hardest part was getting the printf syntax right. When it works, it just works.