Do these three commands do the same thing?
A command that uses grep.
grep "a" -r .A command that uses find.
find . -exec grep "a" {} \;A command that uses a grep on a find through xargs.
find . | xargs grep "a"
|
Do these three commands do the same thing?
| |||||||||
feedback
|
|
They aren't the same and each one have problems.
I would use instead:
It is portable, it ignores non regular files, it won't clash with weird file names and will always show file names when the pattern is found. | |||||||
feedback
|
|
Is this a homework question? Did you try them? They do slightly different things. For example, if you feed | |||||||||||
feedback
|
|
You should better define "do the same thing". The first one runs one command, the second runs one find and fork+exec's grep once per file found, and the third runs a minimum of three commands - or more if too many files are found to fit onto one command line. As far as CPU/memory impact goes, they most distinctly do not do the same thing - the difference between 1, three, and "a whole bunch" of processes is significant. From a filesystem perspective, the filesystem is traversed, each file is stat'd, and then opened, fully read, and closed. So they all do the same thing from that perspective, and the filesystem doesn't notice a difference (aside from perhaps slower traversal in the second instance due to the overhead from forking a bazillion processes). The output genreated to the screen differs, and that difference can be determined empirically buy just running the commands with a few different possible directory structures (one obvious way is that which redgrittybrick mentioned). They consume different amounts of time to type, due to the number of differenc characters and possibilities for syntax errors. And so on. There's lots of ways things can "differ". :) | |||
|
feedback
|