0

Looking over the manual, I can't figure out how to set the date format.

I am using the following to locate folders that are in 'dd-mm-yyyy' name, but realise that it may not be working due to the date format.

Is there any way to set the date format of '-mtime'?

find "${backup_dest}" \
    -maxdepth 1 -type d -mtime +3 \
    -name '[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]' \
    -execdir mv {} $folder_trash_path/{}-"${site[$i]}" ';'
8
  • Your find command is searching for directories, but your question description refers to files. Which is it? Commented Jun 19, 2018 at 11:55
  • @roaima Sorry, its folders. I have changed this in the question.
    – ccdavies
    Commented Jun 19, 2018 at 11:57
  • is -maxdepth 1 throwing you off? (are the directories in question in the $backup_dest directory, or below it?)
    – Jeff Schaller
    Commented Jun 19, 2018 at 12:26
  • @JeffSchaller The folders are directly inside the $backup_dest folder. Here is an example: /Users/myname/Desktop/backups/websites/testsite.co.uk/19-06-2018 - The $backup_dest would be: /Users/myname/Desktop/backups/websites/testsite.co.uk
    – ccdavies
    Commented Jun 19, 2018 at 12:31
  • Just want to point out that the example you just gave is today’s date, and would not pass “-mtime +3”
    – Jeff Schaller
    Commented Jun 19, 2018 at 12:35

1 Answer 1

0

Old find(1) implementatons and the POSIX standard only allow -mtime parameters that are plain numbers and that refer to a time offset that counts in days.

Modern find(1) implementations permit something like: -mtime -3y2m4d referring to all files that have been modified during the past 3 years + 2 months + 4 days.

If you like to refer to a specific time, then you may only use -newer together with a time stamp reference file that could be created with the touch program.

2
  • 1
    It seems to be BSD find that implements units, GNU find doesn't have that yet (BUT IT SHOULD!)
    – deltaray
    Commented Nov 23, 2020 at 19:34
  • @deltaray These units are an obvious idea that I already had around 1988 and sfind, which is based on libfind also supports it. BTW: GNU find was the last find implementation that started to implement -exec ... {} +, so GNU find may not be the leading edge regarding to useful features.
    – schily
    Commented Nov 23, 2020 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .