Delete certain files from specific date in linux

I need a command how I can delete files from a folder with specific date.

Like I want to delete files before 20 April from a folder on /home/FTP and file types are mp4.

Asked By: White hat Mahmud

||

This option "-mtime +12" specifies the modification time of the files.
Here, +12 means files modified more than 12 days ago. Since you want to delete files before 20th April and today is 2nd May, that’s 12 days ago.

find /home/FTP -name "*.mp4" -type f -mtime +12 -delete
Answered By: Ahmed Abdelnaby

You can probably use the -newer with an inversion and a reference file

You first create a reference file dated with your date (in this case 20th of April 2024 at midnight)

touch -d "2024-04-20 00:00:00" /tmp/reference

Then you launch a find using this reference and an "not"

find /yourfolder/ -type f -name "*.mp4" ! -newer /tmp/reference

This should display the files you want to delete.

If the result is what you are looking for, then add -delete at the end of your find.

Answered By: darxmurf
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.