1

So I got the following find command:

find ./test-folder -type d -mindepth 1 -regex "^.*/\d\{4\}-\d\{2\}-\d\{2\}$"

Previously I've created the folder ./testfolder by mkdir testfolder and a folder in it mkdir ./testfolder/2022-10-12.

When running the find command with Bash in an alpine-based docker container everything works fine and it outputs /path/to/testfolder/2022-10-12

If I run the same command in bash on my Lubuntu machine it won't output anything.

I have not modified the find command or anything around it, I expected it to work on any machine, but the regex seems to behave differently. Matching * works, also matching an infinite number of digits \d* works, but as soon as I try to match - or use quantifiers as {4} it won't match anything anymore.

What could be the issue here? Moreover, how can I make it work on LUbuntu?

AdminBee
  • 22,803
Rudolf
  • 13
  • @AdminBee It technically does, but I am still not able to get any regex matching my required format working on Lubuntu. No matter what I try, nothing seems to work.

    Not even -regex "\d\d\d\d-\d\d-\d\d" works for me.

    – Rudolf Oct 12 '22 at 10:56

1 Answers1

1

From a comment I deduce that the actual question is "How do I match the equivalent of \d{4}-\d{2}-\d{2} on LUbuntu".

The problem is two-fold:

  1. First, as explained e.g. in Why does 'find' command on Alpine seem to require escaping '?' but not on Ubuntu?, the default RegEx syntax on AlpineLinux and LUbuntu is different.
  2. Second, the \d character class is part of the "PCRE" style extension of the basic regular expressions, which is not supported on GNU find that comes with Lubuntu.

So, you should use the -regextype option to explicitly select a RegEx type with the features that you need, and then adhere to that style. In your case, you could use the Extended Regular Expression:

find ./testfolder/ -mindepth 1 -regextype "egrep" -regex '^.*/[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}$'
AdminBee
  • 22,803
  • Thank you very much. So it seems there is no interoperable version of regex between busybox and gnu, should I use gnu find in my alpine containers then? Since I'm mostly developing on ubuntu this seems to be good thing to do. I don't think it's practicable to convert the format every time. – Rudolf Oct 12 '22 at 11:11
  • 1
    @Rudolf You're welcome. If you found the answer useful, you may consider accepting it so that others facing a similar issue may find it more easily. As for your question, I don't have much experience with AlpineLinux, but it would seem that the findutils package of AlpineLinux provides GNU find, so the option may be supported there, too. – AdminBee Oct 12 '22 at 11:15