YZlat
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
Is there a way to make it case-insensitive?
for example so that both /u01/data/TEST and /u01/data/Test get returned?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Depending on your OS, you could also do
find $dir1 -type d -iname $word
find $dir1 -type d -iname $word
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.