LinuxQuestions.org
Register a domain and help support LQ
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 03-09-2010, 05:28 PM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
xargs - question


Hi,

I would like to ask the following:

1) ls -l |grep test -> this will grep every "ls -l" output line
2) ls -1 |xargs grep test -> this will grep every single file with test

3) ls -1 |xargs echo -> this will echo directory list
4) ls -1 |echo -> this does nothing!!!

My question is: how some command can recive input from "both sides" (grep can grep whole output or every single file - xargs, the same is for i.e. wc command). 4) echo does nothing (it's a single echo command)

Thank you
 
Old 03-09-2010, 05:40 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
echo expects literal text or the evaluation of a variable---not a data stream. xargs plugs in the output of "ls -1" as if it were the expected string.

Maybe think of it this way: A command that would normally read a file can get it's data from a pipe---eg grep, sed, more--and many others. If the command does not normally read from a file, then you need xargs.
 
  


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
[SOLVED] xargs and cp --parents amchargue Linux - Newbie 7 10-09-2009 01:12 PM
Using xargs SBN Linux - General 2 04-07-2008 08:44 PM
`wc`, `xargs` h/w Programming 11 09-30-2007 05:22 PM
xargs yawe_frek Linux - Software 1 04-15-2007 05:26 PM
xargs question reitzell Linux - Newbie 4 07-04-2004 03:36 AM


All times are GMT -5. The time now is 03:56 PM.

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