LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   xargs command (https://www.linuxquestions.org/questions/linux-newbie-8/xargs-command-4175493774/)

sryzdn 02-05-2014 03:59 AM

xargs command
 
Hi,

I am reading a book on linux essentials. It has explained the function of "xargs" together with "find" command that baffled me.

Although I have understood what xargs does, I need to fully grasp it. In the pool of internet, I just found similar examples for newbs.

Does anyone know a source to make me fully understand this command?

chrism01 02-05-2014 04:28 AM

Best thing with any cmd is to actually try the examples and try to come up with a few variations yourself...
You only really learn a tool (not just *nix cmds) by using it.

sryzdn 02-05-2014 07:03 AM

Quote:

Originally Posted by chrism01 (Post 5111909)
Best thing with any cmd is to actually try the examples and try to come up with a few variations yourself...
You only really learn a tool (not just *nix cmds) by using it.

Ok, let me ask my question this way. In xargs man we read:

Quote:

xargs - build and execute command lines from standard input
Does it mean that in a combination with a command like "find", 'xargs' first reads the stdin and then 'find' will be executed!? I ask this because I mix up stdin and stdout in commands.

colucix 02-05-2014 08:25 AM

The xargs command takes the standard input and uses it as the arguments of the command: for example the command
Code:

find . -name \*.txt | xargs grep pattern
will find all the .txt files in the current working directory, their name are passed to xargs from standard input (through the pipe) and the grep command is executed for every file. In other words: find is executed first, its standard ouput becomes the standard input of xargs (this is the way a pipe works) and xargs executes the grep command taking the arguments from the standard input.


All times are GMT -5. The time now is 04:49 AM.