Searching files..?

hi there

can anyone tell me how to search and copy files under unix?

im writing shell scripts with 'vi' and 'pico'

something like

read directoryName

if [ $directoryName contains any *.src files ]
then
echo Copying the files
copy those *.src files to sub1(another directory) using cp
else
echo No files found!
fi

can someone write the syntax for me PLEASE?

You could even shorten that.. look into the -exec option for find. You may be able to use something like:

find /directory/path -name *.src -exec cp {} /new/directory \;

Hi,

When abusing oombera's input :

for i in `find / -name *src `
do
echo "Copying file $i into /my/dir"

cp -p $i /my/dir/

done

hi oombera, davidg

thanks for replying me..

i dont know how to use the for loop, so it doesnt work for me.. :frowning:

can you use the if statement to do it?
juz keep it as simple as you can..
please...

Nick,

The for statement is essentially the same thing you are trying to do with the IF statement...

you executue a command until the search results run out...

For name in `find ... ... ... ` gives you a loop that will execute the commands after the DO command...the same way that you are trying to do with your IF statement... it is the same thing essentially...

So, when you tuck the "find "command in the for loop, you will get your desired result... Your "found" files will be copied to your destination directory...

For name in `find / -name *src `
do
your command here ... echo blah blah
your command here ... cp $name blah blah
done

You will have to make sure the find command responds wiht the FULL PATH of the file you wish to move or be in the directory you want to search to make it easier to copy it to your $HOME...