List of last updated files in a folder

Find last updated files like this:

find /my/very/new/folder -printf '%T+ %p\n' | sort -r | head -20

This will return last 20 files.

How to Remove files older than N days from a folder?

This is very sensitive operation, since file delete without caution may hurt badly.

Most important part is to precisely define the folder from where you delete the files, and second if possible to set the extension of the files or some repetitive part of the file name.

Just enumerate all files that are older than 12 days for instance

find /var/www/databasebackup -type f -ctime +12 -name 'pro_*.sql'

If you are sure these are the files you need to remove than add the following tail to the last instruction:

execdir rm -- {} \;
find /var/www/databasebackup -type f -ctime +12 -name 'pro_*.sql' -execdir rm -- {} \;

tags: & category: -