1

Trying to find a list of files from a set variable. However the path needs to be specific.

filename=part-of-filename

Does not work:

find $HOME -regextype posix-extended -type f -regex "$filename-[[:digit:]]{4}-connect\.xml"

Also does not work:

find $HOME -regextype posix-extended -type f -regex "$filename-[[:digit:]]{4}-connect\.xml"

Works, but finds too much. Why is it forcing me to use '.*/'? $HOME is completely ignored here.

find $HOME -regextype posix-extended -type f -regex ".*/$filename-[[:digit:]]{4}-connect\.xml"
1

Why is it forcing me to use '.*/'?

From find documentation:

-regex pattern
File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named ./fubar3, you can use the regular expression .*bar. or .*b.*3, but not f.*r3.

  • Thank you. That answers my question. I also realized I can modify the maxdepth and set the start location to narrow down the results. IE: find ${HOME} -maxdepth 1 -type f -regextype posix-extended -regex ".*/${filename}-[[:digit:]]{4}-connect\.xml" – Motorahead Nov 18 '17 at 1:06

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.