Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-04-2012
Registered User
 
Join Date: Sep 2009
Posts: 53
Thanks: 1
Thanked 0 Times in 0 Posts
xargs vs. pipe

I have been using unix on and off for a number of years. I am not a sys admin. I use what I need. I have googled this, but I really can't figure out what is the difference between using xarg and just using a regular pipe? Why do I need to include xarg sometimes and how do I know when I need it?
Sponsored Links
    #2  
Old 05-04-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Location: Switzerland - GE
Posts: 4,633
Thanks: 118
Thanked 256 Times in 245 Posts
You would use xargs when you get an errror message like "too many arguments", or when you want on the same line the output of more than one command, look :

Code:
ant:/home/vbe $ date pwd 
date: bad conversion
ant:/home/vbe $ date;pwd
Fri May  4 16:32:42 METDST 2012
/home/vbe
ant:/home/vbe $ (date;pwd)|xargs
Fri May 4 16:33:04 METDST 2012 /home/vbe
ant:/home/vbe $

Sponsored Links
    #3  
Old 05-04-2012
neutronscott's Avatar
script kiddie
 
Join Date: Jun 2011
Location: Charleston, SC
Posts: 649
Thanks: 18
Thanked 189 Times in 179 Posts
pipes connect output of one command to input of another.

xargs is used to build commands. so if a command needs argument passed instead of input on stdin you use xargs... the default command is echo (vbe's example). it breaks spaces and newlines and i avoid it for this reason when working with files.


Code:
$ printf '%s\n' file1 file2 file3 | xargs touch
$ ls file?
file1  file2  file3

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
difference bewteen pipe, xargs, and exec guessingo Programming 1 10-12-2011 12:28 PM
Display find results, and pipe to xargs mij Shell Programming and Scripting 4 06-19-2011 07:31 PM
Replace pipe with Broken Pipe saj Shell Programming and Scripting 1 04-08-2011 09:18 AM
Pipe to "xargs rm" : filename with spaces coolatt Shell Programming and Scripting 3 02-10-2010 06:32 AM
Removing a filename which has special characters passed from a pipe with xargs jerardfjay AIX 3 05-19-2009 01:01 PM



All times are GMT -4. The time now is 04:48 PM.