by

2

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]

2

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]

You may also be interested in...

Linux Auto ?

sysadmin Source Code is Free Speech And rm -rf *, does it want to be for all radar devices? Aaaa... there are signs on the face...
Continue reading

2 thoughts on “Automatically delete or move to another folder, files older than X days [Linux / SSH Commands]

  1. Fabrizio says:

    why does that command also delete the folder itself? I wish you would just delete the content! is there a solution? Thank you

    1. Stealth says:

      I understand that you have several files in folders and just want to move the files. The folders remain intact. Correct? (GTrs).

Leave a Reply

Your email address will not be published. Required fields are marked *