Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-09-2010, 04:28 PM   #1
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
xargs - question


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, 04:40 PM   #2
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.


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 12:12 PM
Using xargs SBN Linux - General 2 04-07-2008 07:44 PM
`wc`, `xargs` h/w Programming 11 09-30-2007 04:22 PM
xargs yawe_frek Linux - Software 1 04-15-2007 04:26 PM
xargs question reitzell Linux - Newbie 4 07-04-2004 02:36 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:09 AM.

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