-2

I'm new with server maintenance job.

Now I must find and delete .JPG File older than 3 years. on linux terminal

I have googled and found a script like this

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

or

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

I have tried this

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

or

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

But it didn't work, I think my file is too big to be found.

Can anyone help me to fix this..?

Or maybe there's another way?

I would appreciate your answer a lot.

Thanks

drookie
  • 8,625
  • 1
  • 19
  • 29
Uchsun
  • 101
  • 1
  • 2
  • find has nothing to do with file size, and should be able to "find" any file for you. How is it "not working"? Any error messages? Try a find /path/ -mtime +1095 -exec ls {} \; to get a list of the files, and see if that works... – David W Apr 02 '18 at 01:25
  • ok I will try you advice, but when i try this find /path/to/files* -mtime +1095 and enter on terminal, nothing show and nothing error. – Uchsun Apr 02 '18 at 02:21
  • I have try your advice ind /srv/www/htdocs/c-app/fkendaraan/ -mtime +1095 -exec ls {} \; and nothing happen. – Uchsun Apr 02 '18 at 02:24
  • So there's nothing older than 3 years then. – drookie Apr 02 '18 at 04:40
  • @drookie So there's nothing older than 3 years then. ok I know, my issue is, Im Sure that my Data Older than 5 year. but, I have resync it to new server. And the data maybe change date when I resync. is there any other way? – Uchsun Apr 02 '18 at 07:57

1 Answers1

0

You should try this command:

find /path/to/files -mtime +1095 -type f -name "*.JPG" -delete

Is important that you put the -delete parameter at the end.

(From man page of find command: "...Don't forget that the find command line is evaluated as an expression, so putting -delete first will make find try to delete everything below the starting points you specified..."

first to run that you should check the output running:

find /path/to/files -mtime +1095 -type f -name "*.JPG"

(Whithout -delete)

find will search into /path/to/files everything with metadata changed more than 1095 days ago (-mtime +1095), then

-type f will restrict the search only to files type,

-name "*.JPG"
Only the files with de JPG extension will be selected and

-delete will delete everything that was finded (without ask you for conferm your will).

I hope this can help you.

Cheers

  • Thanks for your answer, but after try this find /path/to/files -mtime +1095 -type f -name "*.JPG" nothing happen. I think date file change when I resync to new server – Uchsun Apr 03 '18 at 01:44