Automatically delete or move files older than X days to another folder [Linux / SSH Commands]

countless are options si commands in linux, and I think I would have copied if I didn't have the option to move files older than 120 days from one folder to another.
Here is 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 {} \;

Must necessarily leave spaces -Mtime, Number of days, -Exec (Command line continues) rm (delete command - remove), argument " -f ”(Force delete), {} si \ ;.

It is possible that on some distributions of linux, "-F" should not work. Remove this argument from the line and everything will be ok.

* Tested on CentOS  5.3 (FT).

Founder and editor Stealth Settings, from 2006 to the present. Experience on operating systems Linux (in particular CentOS), Mac OS X, Windows XP> Windows 10 si WordPress (CMS).

How to » Noteworthy » Automatically delete or move files older than X days to another folder [Linux / SSH Commands]

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

  1. why does that command also delete the folder itself? I just want to delete the content! is there a solution? grazie

    Reply
Leave a Comment