Automatically delete or move to another folder, files older than X days [Linux / SSH Commands]
Automatically delete or move to another folder, files older than X days [Linux / SSH Commands]
They are countless choice and CONTROLS in linux, and I think I would have finished if I didn't have the option to move some files older than 120 days from one folder to another.
Here's how we can move some files older than X days:
Commands via SSH :
find /home/cale/fisiere* -mtime +120 -exec mv /noua/destinatie/ {} \;
If we want to delete all files older than 30 days, from a folder …
find /cale/fisiere* -mtime +30 -exec rm -f {} \;
You must necessarily leave spaces between -mtime, number of days, -exec (command line continues), rm (delete command – remove) , the argument ” -f ” (force delete) , {} si \;.
It is possible that on some Linux distributions, “-f” not to work. Remove this argument from the line and everything will be ok.
*Tested on CentOS 5.3 (Final).
Automatically delete or move to another folder, files older than X days [Linux / SSH Commands]
What’s New
About Stealth L.P.
Founder and editor Stealth Settings, din 2006 pana in prezent. Experienta pe sistemele de operare Linux (in special CentOS), Mac OS X , Windows XP > Windows 10 si WordPress (CMS).
View all posts by Stealth L.P.You may also be interested in...
2 thoughts on “Automatically delete or move to another folder, files older than X days [Linux / SSH Commands]”
why does that command also delete the folder itself? I wish you would just delete the content! is there a solution? Thank you
I understand that you have several files in folders and just want to move the files. The folders remain intact. Correct? (GTrs).