Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Is there a good way to grep multiple directories without --include? Post 302909199 by Corona688 on Tuesday 15th of July 2014 11:14:34 AM
Old 07-15-2014
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.

Code:
find ./*/2013/* -type f | xargs grep -l "191684520"

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

moving directories to new directories on multiple servers

Hi - I am new to unix scripts...I need to move several directories on multiple servers to new directories. (0 Replies)
Discussion started by: mackdaddy07
0 Replies

2. Shell Programming and Scripting

extract multiple cloumns from multiple files; skip rows and include filenames; awk

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)
Discussion started by: manishabh
4 Replies

3. Shell Programming and Scripting

check if multiple directories exist else create missing directories

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)
Discussion started by: ramky79
7 Replies

4. Shell Programming and Scripting

Using Grep Include/Exclude Files

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)
Discussion started by: metallica1973
8 Replies

5. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

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)
Discussion started by: vinothrajan55
1 Replies

6. UNIX for Dummies Questions & Answers

Deleting multiple directories inside multiple directories

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)
Discussion started by: kkouraus1
7 Replies

7. Programming

where to put include files, multiple src directories

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)
Discussion started by: LMHmedchem
0 Replies

8. Shell Programming and Scripting

Create a dummy file in all directories that include a .jpg

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)
Discussion started by: Davinator
11 Replies

9. Shell Programming and Scripting

Include information in certain columns using grep and awk

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)
Discussion started by: owwow14
3 Replies

10. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

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)
Discussion started by: Circuits
3 Replies
FASTRM(1)						    InterNetNews Documentation							 FASTRM(1)

NAME
       fastrm - Quickly remove a list of files

SYNOPSIS
       fastrm [-de] [-c|-cI] [-s|-sM] [-u|-uN] base-directory

DESCRIPTION
       fastrm reads a list of either file names or storage API tokens, one per line, from its standard input and removes them.	Storage API tokens
       are removed via the SMcancel() interface.  fastrm does not delete files safely or with an eye to security, but rather cuts every corner it
       can to delete files as fast as it can.  It should therefore never be run on publically writable directories, or in any other environment
       where a hostile party may control the directory structure in which it is working.

       If a file name is not an absolute path name, it is considered to be relative to base-directory as given on the command line.  The base-
       directory parameter must be a simple absolute pathname (it must not contain multiple consecutive slashes or references to the special
       directories "." or "..").

       fastrm is designed to be faster than the typical "| xargs rm" pipeline when given a sorted list of file names as input.	For example,
       fastrm will usually chdir(2) into a directory before removing files from it, meaning that if its input is sorted, most names passed to
       unlink(2) will be simple names.	This can substantially reduce the operating system overhead from directory lookups.

       fastrm assumes that its input is valid and that it is safe to call unlink(2) on every file name it is given.  As a safety measure, however,
       fastrm when running as root will check with stat(2) that a file name doesn't specify a directory before removing it.  (In some operating
       systems, root is allowed to unlink directories, even directories which aren't empty, which can cause file system corruption.)

       The input to fastrm should always be sorted -- or even better be in the order file names are output by find(1) -- if speed is an issue and
       the input isn't solely storage API tokens.  (It deals fine with unsorted input, but is unlikely to be any faster in that case than a simple
       "| xargs rm" command.)  Sorting may even slightly speed up the removal of storage API tokens due to caching effects, since sorting will
       tend to keep all of the tokens from a particular storage method together.

       Various additional optimizations for removing files can be turned on and/or tuned with options (see below).  Which options will be most
       effective depends heavily on the underlying structure of the file system, the way in which directories are stored and searched, and
       similar, often underdocumented, operating system implementation details.  The more sophisticated the underlying operating system and file
       system, the more likely that it will already perform the equivalent of these optimizations internally.

OPTIONS
       -c[I]
	   Controls when fastrm calls chdir(2).  If the number of files to be unlinked from a given directory is at least I, then fastrm will
	   change to that directory before unlinking those files.  Otherwise, it will use either the absolute path names or a path name relative
	   to the current directory (whichever is likely more efficient).  The I parameter is optional; if just -c is given, -c1 is assumed, which
	   will cause fastrm to always chdir before calling unlink(2).	The default is -c3.  Use -c0 to prevent fastrm from ever using chdir(2).

       -d  Don't remove any files.  Instead, print a list of the files that would be removed to standard output.  Each line contains either the
	   current directory of fastrm at the time it would do the unlink and the relative path name it would pass to unlink(2) as two fields
	   separated by whitespace and a "/", the absolute path name (as a single field) that would be passed to unlink(2), or the string "Token"
	   and the storage API token that would be removed.

       -e  Treat an empty input file as an error.  This is most useful when fastrm is last in a pipeline after a preceding sort(1) command,
	   ensuring that fastrm will fail if the sort fails.

       -s[M]
	   When -s is given and the number of files to remove in a directory is greater than M, rather than remove files in the order given,
	   fastrm will open the directory and read it, unlinking files in the order that they appear in the directory.	On systems with a per-
	   process directory cache or that use a linear search to find files in a directory, this should make directory lookups faster.  The M
	   parameter is optional; if just -s is given, -s5 is assumed.

	   When this option is in effect, fastrm won't attempt to remove files that it doesn't see in the directory, possibly significantly
	   speeding it up if most of the files to be removed have already been deleted.  However, using this option requires fastrm to do more
	   internal work and it also assumes that the order of directory listings is stable in the presence of calls to unlink(2) between calls to
	   readdir(3).	This may be a dangerous assumption with some sophisticated file systems (and in general this option is only useful with
	   file systems that use unindexed linear searches to find files in directories or when most of the files to be removed have already been
	   deleted).

	   This optimization is off by default.

       -u[N]
	   Specifying this option promises that there are no symbolic links in the directory tree from which files are being removed.  This allows
	   fastrm to make an additional optimization to its calls to chdir(2), constructing a relative path using "../.." and the like to pass to
	   chdir(2) rather than always using absolute paths.  Since this reduces the number of directory lookups needed with deeply nested
	   directory structures (such as that typically created by traditional news spool storage), it can be a significant optimization, but it
	   breaks horribly in the presence of symbolic links to directories.

	   When -u is given, fastrm will use at most N levels of ".."  segments to construct paths.  N is optional; if just -u is given, -u1 is
	   assumed.

	   This optimization is off by default.

       fastrm also accepts -a and -r options, which do nothing at all except allow you to say "fastrm -usa", "fastrm -usr", or "fastrm -user".
       These happen to often be convenient sets of options to use.

EXIT STATUS
       fastrm exits with a status of zero if there were no problems, and an exit status of 1 if something went wrong.  Attempting to remove a file
       that does not exist is not considered a problem.

EXAMPLES
       fastrm is typically invoked by INN via expirerm(8) using a command like:

	   fastrm -e <patharticles in inn.conf> < expire.list

       To enable all optimizations and see the affect on the order of removal caused by -s, use:

	   fastrm -d -s -e -u <patharticles> < expire.list

       If your file system has indexed directory lookups, but you have a deeply nested directory structure, you may want to use a set of flags
       like:

	   fastrm -e -u3 <patharticles> < expire.list

       to strongly prefer relative paths but not to use readdir(2) to order the calls to unlink(2).

       You may want to edit expirerm(8) to change the flags passed to fastrm.

WARNINGS
       fastrm cuts corners and does not worry about security, so it does not use chdir(2) safely and could be tricked into removing files other
       than those that were intended if run on a specially constructed file tree or a file tree that is being modified while it is running.  It
       should therefore never be used with world-writable directories or any other directory that might be controlled or modified by an attacker.

NOTES
       fastrm defers opening the storage subsystem or attempting to parse any INN configuration files until it encounters a token in the list of
       files to remove.  It's therefore possible to use fastrm outside of INN as a general fast file removal program.

HISTORY
       fastrm was originally written by <kre@munnari.oz.au>.  This manual page was rewritten in POD by Russ Allbery <rra@stanford.edu> for
       InterNetNews.

       $Id: fastrm.pod 8576 2009-08-18 13:55:11Z iulius $

SEE ALSO
       expirerm(8).

INN 2.5.3							    2009-09-11								 FASTRM(1)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy