2

This is the command that I have and would like to modify with an additional condition:

find /home/user/backups/ -mindepth 2 -maxdepth 3 -name "*~EEEE000.tif" -print

This is the output of ls /home/user/backups/:

backup20170101_somerandomstring
backup20170115_somerandomstring
backup20170230_somerandomstring
backup20170305_somerandomstring
backup20170408_somerandomstring
backup20170521_somerandomstring
.
.
.
backup20190111_somerandomstring
backup20190130_somerandomstring
backup20190209_somerandomstring
backup20190301_somerandomstring
backup20190303_somerandomstring
backup20190311_somerandomstring
backup20190313_somerandomstring
backup20190412_somerandomstring
.
.
.
backup20200102_somerandomstring
backup20200103_somerandomstring
backup20200105_somerandomstring
backup20200110_somerandomstring
.
.
.

I only want to search directories that were generated after 2019-03-10. So this can be easily thought of as directories which in their name have numbers larger than 20190310 right after the word backup.

I can thin of seq but do not know how to use it alongside find. And I am sure there are better options out there.

seq -f "backup%1.0f" 20190310 20200131
2
  • Does the date in the directories name match the field "Birth time" returned by applying stat to the directories? Jan 30, 2020 at 10:40
  • @PauloTomé I thought of using newerBt in find but I am using a filesystem that does not store birth time at all.
    – paropunam
    Jan 30, 2020 at 11:58

1 Answer 1

4

Using the zsh shell, the filename globbing pattern <n-m> matches numbers in the range n to m inclusively.

The pattern

/home/user/backups/backup<20190311->_*

would match all names in /home/user/backups that start with the string backup and is immediately followed by a number that is 20190311 or larger, and then an underscore and possibly more characters.

To match only directories:

/home/user/backups/backup<20190311->_*(/)

Using this with your original find command:

find /home/user/backups/backup<20190311->_*(/) \
    -mindepth 1 -maxdepth 2 -name "*~EEEE000.tif" -print

This would search each directory that the glob matches for names of files or directories ending with ~EEEE000.tif (at specific directory depths). It would print the found pathnames. The search depths have been adjusted to account for the extra depth of the search path roots.

Without find, and only printing names of regular files:

print -rC1 -- \
    /home/user/backups/backup<20190311->_*/*'~EEEE000.tif'(.ND) \
    /home/user/backups/backup<20190311->_*/*/*'~EEEE000.tif'(.ND)

This would also resolve symbolic links to directories in the paths though.

4
  • Sounds like the OP would then want: find /home/user/backups/backup<20190311->_*(/) -mindepth 1 -maxdepth 2 -name "*~EEEE000.tif" -print Jan 30, 2020 at 11:06
  • @StéphaneChazelas Ah, I misread the question. Yes, you are correct. Will update.
    – Kusalananda
    Jan 30, 2020 at 11:07
  • @paropunam There are two commands in my answer, one find command and one print command. Which one of these did you run?
    – Kusalananda
    Jan 30, 2020 at 12:18
  • @paropunam Neither of those commands should cause the shell to try to execute a directory (which is what the error message indicates).
    – Kusalananda
    Jan 30, 2020 at 12:30

You must log in to answer this question.

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