I'm working in Linux & bash (or Cygwin & bash).
I have a huge--huge--directory structure, and I have to find a few needles in the haystack.
Specifically, I'm looking for these files (20 or so):
foo.c
bar.h
...
quux.txt
I know that they are in a subdirectory somewhere under .
.
I know I can find any one of them with
find . -name foo.c -print
. This command takes a few minutes to execute.
How can I print the names of these files with their full directory name? I don't want to execute 20 separate find
s--it will take too long.
Can I give find
the list of files from stdin? From a file? Is there a different command that does what I want?
Do I have to first assemble a command line for find
with -o
using a loop or something?
You can insert the output of a grep directly into a command line with command substitution. For example, to edit only the subset of files containing R6, you would type: % vi `grep -l R6 file1 file2 ...`
tar cannot read in file data from stdin for creating an archive, since then tar will have no way of knowing what a file is - where one begins or ends, what its path and metadata is.
You need to use the grep command. The grep command or egrep command searches the given input FILEs for lines containing a match or a text string.
If your directory structure is huge but not changing frequently, it is good to run
cd /to/root/of/the/files
find . -type f -print > ../LIST_OF_FILES.txt #and sometimes handy the next one too
find . -type d -print > ../LIST_OF_DIRS.txt
after it you can really FAST find anything (with grep, sed, etc..) and update the file-lists only when the tree is changed. (it is a simplified replacement if you don't have locate
)
So,
grep '/foo.c$' LIST_OF_FILES.txt #list all foo.c in the tree..
When want find a list of files, you can try the following:
fgrep -f wanted_file_list.txt < LIST_OF_FILES.txt
or directly with the find command
find . type f -print | fgrep -f wanted_file_list.txt
the -f
for fgrep mean - read patterns from the file, so you can easily grepping input for multiple patterns...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With