Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'xargs and working with spaces in filenames' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
xargs and working with spaces in filenames
Authored by: robleach on Jul 21, '09 01:19:09PM
You can also use the -exec or -execdir option to find:
find . -type f -execdir egrep whatever {} \;
Incidentally, is egrep the same as "grep -E"? Looks like it. Why does that bother me? ;-) Rob

[ Reply to This | # ]
xargs and working with spaces in filenames
Authored by: CarlRJ on Jul 21, '09 02:08:42PM

Yes, egrep is the same as "grep -E"; this is historical, grep was the original command, followed by fgrep ("fast grep") that was very quick but doesn't grok wildcards, and egrep ("enhanced grep") that understood full regular expressions. Later on, these three programs were folded back into one (with 3 hardlinks to the same executable), then the "-E" and "-F" options were added.

Related trivia: the name "grep" comes from "g/re/p" (where "re" is short for Regular Expression), a much-used command in the ed, ex, and vi editors to find lines matching the given regular expression anywhere in the file (i.e. "G"lobally), and "P"rint the result. Someone decided this capability would make a nifty command line utility, instead of starting up an editor to search a file, thus "grep".

Oh, and you're generally better off using a "+" instead of a ";" at the end of that find command for anything that's going to handle a lot of files, since the "+" version will run a minimal number of long command lines, each with as many filenames as possible (thus starting up grep, or whatever, a relatively small number of times), while the ";" version will run (grep or whatever) one time for every file (thus potentially many MANY more processes). As a bonus, since grep will get more than one filename at a time, it'll print the filenames at the start of each matching line.



[ Reply to This | # ]
xargs and working with spaces in filenames
Authored by: spfolly on Jul 21, '09 02:51:36PM

One of the points in the original post (and indeed the title!) - is working with *spaces* in filenames. Your example should have quotes around the {}



[ Reply to This | # ]
xargs and working with spaces in filenames
Authored by: CarlRJ on Jul 21, '09 03:50:41PM

Actually, no. Quotes on the command line are only to get around the shell's default command line processing. Whether or not you put quotes around {}, the argument that <tt>find</tt> gets will not have quotes. And it doesn't need them, as the command will not be reinterpreted by any more shells (where quoting might matter), it'll get fork'd and exec'd directly from find with no further processing of the arguments.



[ Reply to This | # ]