My company has a set of linux servers that users store files on. The files following a common naming scheme of #####,###,### with the numbers correlating to fields unique to them. They are supposed to remove the files after 30 days but that is not happening and as a result of a growing user community some of the servers are running low on disk space.

Does anyone out there know of a way I could script a process that would search all the partitions of the linux servers for any file with the above naming scheme that would be older then 30 days and move it to a new folder?

That would make it so much easier to clean up because some of the users store files many levels deep and its starting to occupy to much time just looking for them let a lone deciding whether or not it can be deleted.

Any help would be greatly appreciated!

1 Answer 1


Use the find command to get the files you want. You can use the -mtime option to set the age of the file. You can use the regex \d{5},\d{3},\d{3}$ to match the file name. Then move each file to wherever you want.

Like this:

find / -mtime +30 -regex '\d{5},\d{3},\d{3}$' -exec mv {} /path/to/destination/folder \;
  • The above unleashes this on the root which is pretty scary. Consider containing it to just the directories you need.
  • Note that that pattern is not extremely unique, so again use with caution.
  • Fine tune your regex here
  • 1
    -exec mv -t dest {} + will be more efficient. That runs mv with big batches of filenames. As you say, searching the whole system seems like a strange requirement. You can probably save a lot of time by just giving some specific paths to search, and or using -prune to filter the results. Obviously you can test it before using with mv, by using a command like ls instead. Sep 23, 2015 at 23:05
  • Peter, would this look correct to list the results? find / -mtime +15 -regex '\d{5},\d{3},\d{3}$' -exec ls -ld {} \;
    – mrbarker
    Oct 7, 2015 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .