Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search mateched file names in a big directory?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I am learning AWK and new to it. Here is my question:

I have a very big directory that looks like directory tree. My purpose is to find out one kind of matched file, for example, only *.awk file in all subdirectories and store them in a new created directory call new_awk.

I don't know how to do. Appreciate any help. Thanks.
 
There's a lot of ways of solving this one, but probably the simplest is using find. Do something like this:

for i in `find . -name "*.awk" -print`
do
cp $i new_awk
done

The above copies all files ending in awk from the current directory. Do a man find for other options.

Regards,

Ed
Schaefer
 
no need for a "fo r" loop.

"man find" and pay attention to "-exec" option

vlad
 
find . -name '*.awk' -exec cp {} new_awk \;
Jean Pierre.
 
Hi all,

Thanks alot for your help. It works well under one directory. I wanted it to search all subdirectories. One more example: suppose under a root directory called AWK there are 10 levels of subdirectories all have *.awk files. I don't know how to shift subdirectories with this script.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top