Re: Program to scan directories




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

.



Relevant Pages

  • Re: MacTeX 2007 and documentation
    ... may be the most useful command available when doing searches at the ... will find every file on your system that has the text "memoir" on it, ... If locate generates 30 lines of text, where each line is a file, grep ... I need a Unix guru to chat to for half an hour or so to put me straight. ...
    (comp.text.tex)
  • Re: piping multiple selections to mv or cp and exclusion
    ... pipe to shell to execute each command statement ... Unix is indeed lifelong learning :-) ... and the regexp. ... back into the grep statement. ...
    (comp.unix.shell)
  • Re: MacTeX 2007 and documentation
    ... means you need expertise in your host operating system as well. ... locate memoir | grep pdf ... I'm not someone who lives at the command line, ...
    (comp.text.tex)
  • Re: Using the grep command to filter
    ... I am a college student currently enrolled in a Unix class. ... that ubuntu Ubuntu UBUNTU ubunTU whatever in them. ... grep ubuntu /etc/* of course. ... Now look at the output of that grep command will give you all the ...
    (comp.unix.shell)
  • Re: Program to scan directories
    ... Is there a UNIX command which scans directories and execute any other ... The problem is that grep apparently has an error and works correctly ... tell grep to recurse through the kpathsea directory (the *.h regex ...
    (comp.unix.programmer)