in my folder I have file which suffix is date when this file was created for example:
file.log2012-08-21, file.log2012-08-20 … Now how I can move file which is older then 2012-08-20 ? I know how I can do this day by day: mv file.log2012-08-19 /old/ but I dont know when to stop … is there some parameter in command mv to do this easier ?
in my folder I have file which suffix is date when this file was
Share
ls -l | awk '{print $NF}' | awk 'substr($0, length($0)-9, length($0)) < "2012-08-20" {system("mv "$0" /old/")}'This will move all the files older than “2012-08-20” to the folder “/old”. Likewise, you can change the “2012-08-20” to specify particular date you want. Note this assumes that the file suffix is a date stamp, but the prefix can be any name.
If you just need to move files older than a certain days, then I think rkyser’s answer is better for that.