UNIX Command Line - How to "find" directories using embedded wildcard

2.8k Views Asked by At

I want to find all/any directories on a UNIX Server named "2", but I only want them within a certain directory structure name "/home/abc/public_html".

I tried this:

find / -type d -name "/home/abc/public_html/*2"

But I got the error

find: warning: Unix filenames usually don't contain slashes (though pathnames do).

1

There are 1 best solutions below

19
On BEST ANSWER

Add a condition with -a:

find . -name '*/home/abc/public_html/*' -a -name '*2'

Or, as seen in comments:

find / -type d -wholename "*/home/abc/public_html/*2"

Because you were getting the error

find: warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '-name /home/vps/public_html/'' will probably evaluate to false all the time on this system. You might find the '-wholename' test more useful, or perhaps '-samefile'. Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ /home/vps/public_html/''."