[Linux] Count Files and Delete Old Files
Posted: 15 Jun 2011, 10:41am - Wednesday

Here's the command to count the files inside a specific directory under linux environment:

ls -1 <target path> | wc -l
Here's the command to delete all files older than 60 days within specific directory:
find <target path> -mtime +60 -type f -exec rm -rf {} \;
Here a sample to delete PNG files after 3 days.
find /home/proj/public_html/cache/ -mtime +3 -name '*.png' -type f -exec rm -rf {} \;
It help a lot for file management combined with cron jobs.