Need help with UNIX find command

I need to find a list of all subdirectories of $dir1 that contain word "TEST", and not just at the end, but anywhere in the path.

I am using the following:


find $dir1 -type d -name '*'$word'*' -print

it is working but seems to only retrieve those path that end with TEST:


For example /01/data/TEST contains a subdirectory lists but it does not output  /u10/data/TEST/lists

How can I modify my code to display subdirectories of TEST as well?
LVL 35
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Why not simply

find $dir1 -type d |grep $word

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Just skip -name option and use grep instead

find $dir1 -type d -name '*'$word'*' -print


find $dir1 -type d  -print | grep "$word"

-name option is used for file/directory at the end of the path.
YZlatAuthor Commented:
grep worked as desired! Thanks!

Is there a way to make it case-insensitive?

for example so that both /u01/data/TEST and /u01/data/Test get returned?
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

find $dir1 -type d |grep -i $word
YZlatAuthor Commented:
Depending on your OS, you could also do

find $dir1 -type d -iname $word
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.