LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-05-2014, 04:59 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 253

Rep: Reputation: 1
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?
 
Old 02-05-2014, 05:28 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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.
 
Old 02-05-2014, 08:03 AM   #3
sryzdn
Member
 
Registered: Feb 2013
Posts: 253

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by chrism01 View Post
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.
 
Old 02-05-2014, 09:25 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 7 05-21-2014 08:26 PM
[SOLVED] xargs command not working with ssh sudhanshu_t Linux - Server 4 09-09-2013 12:53 PM
Command line : xargs and rm Seb-o-tronic Linux - General 11 04-02-2013 11:32 PM
[SOLVED] basename with command substitions and xargs dugan Programming 3 06-21-2011 10:58 AM
clarification on find + xargs rm command dtra Linux - General 2 05-17-2006 06:56 AM


All times are GMT -5. The time now is 02:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration