|
it is never quite that easy, are there any subdirectories to worry about (your command for the ls included the -r option?
for that possibility, the best option would be
find ./ -type f -name '*.z' -exec ls -l {} \; | awk '$8 == 2005{print $nf}' | xargs rm -f
of course, you could use a system command in awk, but i prefer to do that outside the awk.
this assumes your system supports all these commands.
basically, this says - for all files in this directory and all subdirectories whose filename ends with a .z, do a long listing of it, see if the year is 2005 and if so print only the file name (including directory), and for those passing through the awk, do a "rm -f" on them.
technically, it is possible to add the mtime to the find to choose only those for 2005, but i agree that it just as easy to use the awk as this filter. however, using the right mtime parameters, it could all be done in one command (without pipes) by doing
find ./ -type f -name '*.z' -mtime +days -mtime -days -exec rm -f {} \;
but i am too lazy to calculate what the two days parameters would need to be.
|