Is there a good way to grep multiple directories without --include?
Hello.
I consider myself a journeyman Unix user. I can handle most day to day tasks and have created some fairly complicated command queries, but this problem has defeated me so far. Any help would be greatly appreciated!
We keep an archive in the file system with a directory structure in the form of
When we need to find data in the archive we do a recursive search with grep. This worked fine for awhile, but now that we have several years worth of data it is taking too long. I would like to narrow the search by year, but I can't figure out a good way to do so since the year is two directory levels down. I've found answers on Google, but most use "--include" which my version of grep does not allow (AIX).
I have found one command that works, but it is still very slow:
I also don't understand why I have to include the -r flag, but
does not work
Is there anything I can do to make this go faster? I've experimented with using xargs instead of the -exec flag, but don't really understand it.
You need -r because you are telling find to find directories, and only directories, via -type d.
As for speeding it up it is quite possibly running at maximum speed already -- there's no "extra-fast" way to read a directory short of speeding up the disk. But you could try improving it with xargs so it doesn't run grep more times than it needs to. This may mess up if your file or directory names contain spaces.
You need -r because you are telling find to find directories, and only directories, via -type d.
As for speeding it up it is quite possibly running at maximum speed already -- there's no "extra-fast" way to read a directory short of speeding up the disk. But you could try improving it with xargs so it doesn't run grep more times than it needs to. This may mess up if your file or directory names contain spaces.
I guess I don't understand the -exec flag as well as I thought I did. I thought that I was gathering a list of directories to feed the grep command. Obviously I have a lot to learn. Thank you very much for your help!
If there is any chance that any filenames in your file hierarchy contain whitespace characters (space, tab, or newline), xargs won't work. Even in cases where it will work, using it is usually inefficient. It will probably also go faster if you let find walk the directories instead of having the shell give a longer list of directories to find to process (and may also avoid arg list too long issues). Instead of:
try:
This User Gave Thanks to Don Cragun For This Post:
Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried:
grep -lr "this string" *
but I do not... (3 Replies)
HI all,
I have data in a file that looks like this:
1 HOW _ NNP NNP _ 3 nn _ _
2 DRUGS _ NNP NNP _ 3 nn _ _
3 ACT _ NNP NNP _ 0 null _ _
4 : _ ... (3 Replies)
Hello. My latest project has me with the need for the following script. Basically, any directory that includes a .jpg file needs to also have a ".picture" file created (if it doesn't exist). Here's an example of what I need.
/mnt/user/Pictures/2011/Hawaii - 2011/.picture... (11 Replies)
I have an issue with some fortran include files.
I have the following src directory structure,
trunk/src/client_main
trunk/src/client_models
trunk/src/server
The make file is at trunk/makefile.
In /src/client_main there are some included dependencies,
COMMON.BLK
PARAM.DAT... (0 Replies)
Hi,
Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly.
I have directories (eg 40001, 40002, etc) that each have one subdirectory (01).
Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir.
I need to keep the top and... (7 Replies)
Hi all,
Using grep command, i want to find the pattern of text in all directories and sub-directories.
e.g: if i want to search for a pattern named "parmeter", i used the command
grep -i "param" ../*
is this correct? (1 Reply)
I wrote this korn script and ran into a hole. I can use find to exclude all the hidden directories and to use my include file/exclude files for running a full backup
find / -depth -ipath '/home/testuser/.*' -prune -o -print| grep -f include.mydirs | grep -v -f exclude.mydirs
but when I... (8 Replies)
Hi ,
I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory.
how to write this in a simple script, I have made my code complex
if ; then
taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Hello,
I am trying to write a bash shell script that does the following:
1.Finds all *.txt files within my directory of interest
2. reads each of the files (25 files) one by one (tab-delimited format and have the same data format)
3. skips the first 10 rows of the file
4. extracts and... (4 Replies)