0

I have 1 folder with image .jpg file, and I'm sure that folder image older than 5 years.

Now I must delete image older than 3 year.

I know i can find it with this

find /path/to/files* -mtime +1095 -exec rm {} \;

or

find /path/to/files* -mtime +1095 -delete;

But Nothing Happen.

My issue is that I think date modified file has been change because I have Resync it to other server when down.

How can I delete that file, without scaning on modified date?

I'm Very Appreciate your answer.

Thanks

  • Which filesystem? – Hauke Laging Apr 4 '18 at 7:56
  • First check whether those files are listing or not by replacing 'rf' with 'ls'. If they were older than 3 years then you will get all those files. – erTugRul Apr 4 '18 at 9:59
  • @HaukeLaging Debian 8 – Uchsun Apr 5 '18 at 4:11
  • @NaushadAhmad "find /path/to/files* -mtime +1095 -exec ls {} \;" is what you mean? the result "bash: /usr/bin/find: Argument list too long " anything wrong? – Uchsun Apr 5 '18 at 4:16
  • Ok, see my answer, hope it will resolve. – erTugRul Apr 5 '18 at 4:50
2

If the EXIF tags in the images are correct, you can use exiftool to change the file modification date to the one given by the tags, and then use find to delete the old ones.

  • OK I will Try it, but I'm still dont have experience with EXIF. I will googling for it. – Uchsun Apr 4 '18 at 7:36
0

Browse to the current directory where all those old files are located:

cd /path/to/the/directory

Check if you can see all those old files:

ls

Now run this command

find . -mtime +1095 -exec rm -Rf -- {} \;

Done!!!

  • hi I have try your answer, ls command can list it, but I must stop it because to huge. After du -sh that file size is 17 Gb and after running your advice, nothing happen. and check again SiZe still 17 GB. – Uchsun Apr 5 '18 at 7:29
  • ok try this again and show me the output find . -mtime +1095 -exec rm -rf {} \; – erTugRul Apr 5 '18 at 7:32
  • Sir, on my question, i have try this "find . -mtime +1095 -exec rm -rf {} \;" and nothing happen. The issue is, Modified date on file has been changed after I have Resync from old Server to New Server. Now I Think I must Find and Delete the Old File not with file Modified Date. because it will search nothing older then 3 years. I hope you know what I mean. Any Idea? – Uchsun Apr 5 '18 at 7:39
  • I understand it but you already mentioned in your previous comment that while listing using ls instead of rm, you got Argument list too long. That means there are files available which are of more than 3 yrs old. So, to resolve it I asked you to use find . (dot) after browsing to that directory. without using -- as I said in comment. So, please try once more this command-- find . -mtime +1095 -exec rm -rf {} \; (make sure your are in that directory) – erTugRul Apr 5 '18 at 7:48
  • Hi Sir, I'm sure, and I have try once again on my directory, I try it "find . -mtime +1095 -exec rm -Rf -- {} \;" and after enter, it nothing happen. if I can upload an image I will Upload it for you. Thanks for helping me. But Any Idea again? Hans Martin gave me answer must using EXIF , but I dont know how to use it. – Uchsun Apr 5 '18 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.