Remove files in unix

Hello,

Could you please tell me how to find all image files which older than 3 monthes in specific directory and in all subdirectories
deriklogovAsked:
Who is Participating?
 
sandeshjConnect With a Mentor Commented:
find /path/dir -name '*.jpg' -mtime +90 -delete

This would delete all jpg files modified more than 3 months back.
0
 
amitnepalCommented:
find / -name '*.jpg' -atime 90

you can replace / by your directory path and jpg with image extensions that you want to look for.

Hope this helps
0
 
amitnepalCommented:
did you wanted to delete ?

atime is to look by access time

and mtime is to look by modification time.

you can use as per your requirement.
0
 
deepak_iqCommented:
find /dir -name '*.jpg' -atime +90 -exec rm -rf {} \;

But to confirm you can slightly modify this as:

find /dir -name '*.jpg' -atime +90 -exec ls -ld {} \; >> /tmp/any_file
cat /tmp/any_file
so now if you want you can directly execute the first step or you can select the particular files from /tmp/any_file for selected removal.
0
All Courses

From novice to tech pro — start learning today.