Linux – Delete old files in a folder

bashlinux

How can I delete all files that are older than one year in a specific folder with the bash under Linux?

Best Answer

find /u1/database/prod/arch -type f -mtime +3 -exec rm {} \;

vi samefilename 
#!/bin/bash

find /u1/database/prod/arch -type f -mtime +3 -exec rm {} \;

The only 2 commands used are find and rm.

Find looks for files (-type f), this to exclude directories, that are older then 3 days (-mtime +3). All it finds is given to rm (-exec rm {} \; ).

You could also place the rm statement outside of find, which is supposed to be faster:

find /u1/database/prod/arch -type f -mtime +3 | xargs rm