Stuck with a simple find problem

Hi,

Need some simple find help.

I need to search for all .so files within sol directory.

My directory tree has mix of directories and i want to search only inside sol directory.

I could get this done combining find with for, any option to do this with find alone.

for a in `find . -type d -name solaris`; do ls $a/*.so 2>/dev/null; done;

# find /path/sol -type f -maxdepth 1 -name "*.so" -print

It will find all .so files inside /path/sol till 1 level deep.

I have a case where there can be sol folders inside nth level of hierarchy.
eg.

/path/sol
a contains b contains sol

How do i go here.

Try --

# find /path/sol -name "*.so" -print

OR

# find /path/sol | grep .so ---> Would be listing all files with .so as suffix

Enjoy !!
Adhir

That will find .so if there are inside any folder other than sol.

cd /path/sol
find . -name "*.so" | grep sol

Hope this helps[/FONT]

I'll give a directory tree.

I am in A.

A contains 3 folders B, C & D.
Now B contains folders named 1, 2 & 3.
C contains folders named 3, 4 & 5.
D contains folders named 3, 6 & 7.

I want to find all .so files under 3 folder.

find A -name "*.so" | grep '\/3\/'

find /path/sol | grep .so | grep 3

1) find /path/sol ----> would list all files in /path/sol
2) grep .so --> would list all files that end with .so
3) grep 3 --> would list all files (path) that contains "3"

Adhir

Have a look at my first post.

I have it already done with a combination of for and find. :stuck_out_tongue:

I wanted it to be done with find alone.

Is there any option? :confused:

I do not find any do loop or for loop in the line mentioned above.

I am using piping here.

find /path/sol | grep .so | grep 3

Adhir

You are using grep :slight_smile:

Means grep via piping.

I want it to be done via only find.

Hi.

My understanding is that you wish to identify any file, anyname.so, that is in a directory named sol, so that the important part of the pathname is sol/anyname.so. There may be other .so files in other directories, but you do not wish to identify those.

If that is so, then here is a script that creates a small tree, including sol and sol/sol and creates files t(n).so in those directories. It then uses the regular expression feature in find to identify the paths which contain the string of interest. In particular there are .so files in directories not named sol, which should not be listed:

#!/bin/sh

# @(#) s1       Demonstrate regular expressions in find.

echo " sh version: $BASH_VERSION"

# Destroy and re-create directory structure.

DIRS="a sol sol/b sol/b/sol sol/sol"
rm -rf $DIRS
mkdir $DIRS

i=1
for d in $DIRS
do
  touch $d/t${i}.so
  (( i += 1))
done

echo
echo " Small tree showing files *.so in directories."
tree .

echo
echo " Results from find using regular expression predicate regex:"
find . -regex '.*/sol/[^/]*so'

exit 0

Producing:

% ./s1
 sh version: 2.05b.0(1)-release

 Small tree showing files *.so in directories.
.
a
/     t1.so
readme.txt
s1
sol
/     b
/     /     sol
/     /     /     t4.so
/     /     t3.so
/     sol
/     /     t5.so
/     t2.so

 Results from find using regular expression predicate regex:
./sol/b/sol/t4.so
./sol/sol/t5.so
./sol/t2.so

There are many examples of find at http://amitsharma.linuxbloggers.com/how\_to_find.htm ... cheers, drl