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]}" ';'
  • Your find command is searching for directories, but your question description refers to files. Which is it? – roaima Jun 19 '18 at 11:55
  • @roaima Sorry, its folders. I have changed this in the question. – ccdavies Jun 19 '18 at 11:57
  • is -maxdepth 1 throwing you off? (are the directories in question in the $backup_dest directory, or below it?) – Jeff Schaller Jun 19 '18 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 Jun 19 '18 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 Jun 19 '18 at 12:35

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.

| improve this answer | |

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.