find -mtime files older than 1 hour

BashShellCommand LineCron

Bash Problem Overview


I have this command that I run every 24 hours currently.

find /var/www/html/audio -daystart -maxdepth 1 -mtime +1 -type f -name "*.mp3" -exec rm -f {} \;

I would like to run it every 1 hour and delete files that are older than 1 hour. Is this correct:

find /var/www/html/audio -daystart -maxdepth 1 -mtime **+0.04** -type f -name "*.mp3" -exec rm -f {} \;

I am not sure of my use of the decimal number??

Thanks for any corrections.

EDIT

OR could I just use -mmin 60? Is this correct?

EDIT2

I tried your test, good thing you suggested it. I got an empty result. I want all files OLDER than 60mins to be deleted! How can I do this?? Does my command actually do this?

Bash Solutions


Solution 1 - Bash

What about -mmin?

find /var/www/html/audio -daystart -maxdepth 1 -mmin +59 -type f -name "*.mp3" \
    -exec rm -f {} \;

From man find:

-mmin n
File's data was last modified n minutes ago.

Also, make sure to test this first!

... -exec echo rm -f '{}' ;
^^^^ Add the 'echo' so you just see the commands that are going to get
run instead of actual trying them first.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbsView Question on Stackoverflow
Solution 1 - BashSean BrightView Answer on Stackoverflow