Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

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:

word="TEST"

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


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


/u02/temp/TEST_01
/u02/data/TEST
/u01/data/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?
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just skip -name option and use grep instead

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

to

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

-name option is used for file/directory at the end of the path.
Avatar of YZlat

ASKER

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

Thanks!
Avatar of Tintin
Tintin

Depending on your OS, you could also do

find $dir1 -type d -iname $word