How To Remove Files Older Than 1 Day/1 Week/1 Month Recursively

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-remove-files-older-than-1-day-1-week-1-month-recursively/
PINTEREST
PINTEREST
INSTAGRAM

We are decent with scripting language bash and not now hot to remove older files for example 1 day. rm command do not have this type of option to use easily. I think adding this type of feature make a lot of system administrators more happy.

Remove Older Than 1 Day

We will use following find command example which is explained in detail below.

  • find is the command we use
  • /tmp is the directory where files resides
  • -mtime provide time option and +1 means older then one day
  • -type provides file types here we set file but we can use directory, socket etc
  • name ‘*.tmp’ filters files according to their names. we just want tmp extension files
  • And the magic resides here -delete will delete the files matching provided criteria

Remove Older Than 1 Week

We can use the same script in order to remove files with extension tmp from /tmp directory with the following script. As a week is 7 days we can use +7 to specify a week like below.

Remove Older Than 1 Month

We can use the same script in order to remove files with extension tmp from /tmp directory with the following script. As a month is 30 days we can use +30 to specify a week like below.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-remove-files-older-than-1-day-1-week-1-month-recursively/
PINTEREST
PINTEREST
INSTAGRAM
LEARN MORE  Linux rm Command Tutorial With Examples