Re: Program to scan directories
- From: vonrog@xxxxxxx
- Date: Wed, 08 Aug 2007 08:42:57 -0700
Lew Pitcher wrote:
On Aug 8, 10:37 am, von...@xxxxxxx wrote:
Hello,
Is there a UNIX command which scans directories and execute any other
command?
Yes. Read the manpage for the find(1) command
Have read, but misunderstood something. It does not work as expected.
tcsh>find -name "*.txt" -exec ls ;
find: missing argument to `-exec'
What does it want?
.....
Remember, the regex you specify here is /not/ given to grep to
process. Instead, the /shell/ expands it by matching to the cwd, and
gives grep the list of matched files. How many of your subdirectory
names will match the *.h regex? Certainly, your kpathsea subdirectory
won't match, and thus grep won't even be told to look there.
Grep's -R option only works against the directories that are listed in
the commandline.
When you said
grep -R DBL_MAX *
the shell expanded the * into a list of all the matching directory
entries (files and subdirectories). grep checked the given filenames
and recursed through the given directory names
When you said
grep -R DBL_MAX *.h
the shell expanded the *.h int a list of all the matching directory
entries (files mostly - you probably have no directories called
something.h). grep /still/ checked the given filenames, and recursed
through the given directory names. Unfortunately for you, you didn't
tell grep to recurse through the kpathsea directory (the *.h regex
didn't match the name "kpathsea"), so of course, the results were not
the same as the previous check
For what it's worth, you should try
grep -R DBL_MAX .
instead. You'll be interested in the results.
This gives the same results as with *. Perhaps it scans all files in
all subdirectories (including
leading directory).
But how can I scan choosen files (like *.h) in the current directory
and ALL subdirectories.
Since I wrote the first post, I have already found --include option of
grep.
It gives additional possibilities but does not solve the problem.
The command like
grep -R --include=*.h DBL_MAX *
or
grep -R --include="*.h" DBL_MAX *
(strange that they give the same result as if there is no name
expansion by shell)
search in ALL files in the current directory and files *.h in ALL
subdirectories.
The second is OK, but the first is NOT.
The command
grep -R --include=*.h DBL_MAX *.h
will search in files *.h n the current directory (OK) but also files
*.h (OK) in directories *.h,
which is not OK.
So how can I scan choosen files (like *.h) in he current directory
and ALL subdirectories?
Regards
Igor
.
- Follow-Ups:
- Re: Program to scan directories
- From: Paul Uiterlinden
- Re: Program to scan directories
- From: Stephane CHAZELAS
- Re: Program to scan directories
- References:
- Program to scan directories
- From: vonrog
- Re: Program to scan directories
- From: Lew Pitcher
- Program to scan directories
- Prev by Date: Re: Program to scan directories
- Next by Date: Re: Program to scan directories
- Previous by thread: Re: Program to scan directories
- Next by thread: Re: Program to scan directories
- Index(es):
Relevant Pages
|