PDA

View Full Version : simple bash program using find



Arical
09-20-2006, 10:21 PM
Im working on a small project and Ive looked, what seems like everywhere, for an answer. My question is Im trying to create a bash shell that will take in two variables and search for files that contain both of the listed arguments. Just for the records, im quite new to linux, so if im making rediculously stupid mistakes thats why :)
one of the million things ive tried :

find . -name "*$1*" -print | xargs find . -name "*$2*
I have looked for ways to include both, but I just cant seem to get it to work.

find . \( -name "*$1*" -a -name "*$2*"\)
but even that doesnt work, im also not to sure if thats how you do AND. I saw it on a website for OR, but they did not describe how to use it properly, and I havent been able to find adequate resources on either.

Any help would be greatly appreciated.
Thanks in advance,
Brett

Salem
09-20-2006, 11:09 PM
> search for files that contain both of the listed arguments.
So if you're searching for 'foo' and 'bar', then you would match a file called
foobar.c
But not files called
foo.txt
bar.dat



find . -type f | grep $1 | grep $2

kawk
09-21-2006, 03:26 PM
How about:


find -name *$1* | grep $2

That works for directorys as well.