They are especially useful for processing lines.

可以看到最终选择出的是这些文件名。 而对于第二个命令:find . You can simplify the above using redirections instead of cat: < file1.txt xargs -I{} sh -c '< file2.txt grep -e "$1"' sh {} Or simply pass the file names as argument to grep instead of using redirections in which case you can even drop the sh: < file1.txt xargs -I{} grep -e {} file2.txt The first two are bang on; the third is slightly off. xargs是 Unix 系统的一个很有用的命令,但是常常被忽视,很多人不了解它的用法。 本文介绍如何使用这个命令。 一、标准输入与管道命令. xargsはEX-argsと読み、引数を組み合わせるという意味を持ちます。xargsコマンドは標準入力からリストファイルを読み込み、引数のコマンドラインにそのリストファイルのアイテムを渡して、実行することができます。 find /dir -type f -print0 | xargs -0i cat {} | grep whatever This will find all files in the /dir directory, and safely pipe the filenames into xargs, which will safely drive grep. Show Matching Lines # show lines containing xyz in myFile grep 'xyz' myFile – dougBTV Mar 19 '15 at 18:52 Yes xargs -0 was the only constructive thing you pointed. -name '*.py' |xargs grep test刚开始的时候,我不熟悉xargs命令,所以直接使用的命令是1 find . This page is a basic tutorial on using Linux shell's text processing tools. cat nameslist.txt | xargs -I {} grep {} targetfile.txt or (without the useless use of cat) < nameslist.txt xargs -I {} grep {} targetfile.txt However, assuming your list has one name per line you don't need xargs here at all - grep can read a list of patterns (or fixed strings, with the -F option) from a file: grep -F -f … Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. So the purpose is served by cat. But did not show the usage. Secondly, the wealth of options can be overwhelming.Thirdly, it was written overnight to satisfy a particular need. If your grep does not provide -h the use cat: find //hp -iname '*.ppd' -print0 | xargs -0 cat | grep "\*ModelName\:" Also, for your information, find provides the -exec option which would render xargs unnecessary had you wanted to pursue your second option: In the following example, find command provided all the .c files as input to xargs.

The manual tells me that -i is deprecated in favor of -I so maybe worth taking a look at that too.

I need to traverse through all sub-directories of a certain directory and 'cat' the …

grep is the most important command. Skipping xargs is not a good idea if you have many thousands of files in /dir; cat will break due to excessive argument list length. -name '…

The OP wants to use cat to print the file content on stdout. find | xargs cat Hi, I am having trouble getting a combination of commands to work. The question is how to use cat from the out put of find command to print the content of the file not how to use sudo or find , The above command solves the question. So xargs ran grep at least twice (because you fed it so many files that they would exceed the maximum command line length, which you limited to 100 files) and at least one of the invocations was on a set of files which contained no matches, which caused the exit code from grep to be nonzero (failure). find,xargs,grep和管道 问题相信大家都知道在目录中搜索含有固定字符串文件的命令:1 find .