0

Say I'm trying to find a file name that contains the two words One and Two. The sequence must be in that order e.g. ./fksklknejnwjOnesvjnh9uibivuwTwojnwovno. At the same time, I would want to exclude any files that contain the words in opposite order, like ./fksklknejnwjTwosvjnh9uibivuwOnejnwovno.

So far all I got is the following, which does not exclude files with tho words in the wrong order:

find . -type f -name "*One*" -name "*Two*"

Any help would be appreciated and sorry if this question is very basic. Just a beginner and first time posting here.

1
  • Look for One wildcard Two ... all three in one search term Commented Feb 14, 2022 at 7:12

1 Answer 1

3

The -name test in find uses a common filename globbing pattern. The pattern *One*Two* matches any name that contains the two substrings One and Two in that order.

Therefore:

find . -type f -name '*One*Two*'

With -name '*One*' -name '*Two*' you would find files with names containing both strings, in any order. Since each individual test is true for files with the words in the "wrong" order, this will give you the files that you want to exclude.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.