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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-14-2009, 10:58 AM
|
#1
|
|
Member
Registered: Dec 2008
Posts: 35
Rep:
|
Piping Output of a Command Like Find
I want to search for a particular file. However, once that file is found I want a long listing of it to see it's permissions. If I do something like this: "find / -name whatever | ls -l" it just gives me the result of "ls -l". What am I doing wrong?
|
|
|
|
08-14-2009, 11:02 AM
|
#2
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
Here's one option:
Quote:
|
find . -name MYFILE -exec ls -l {} \;
|
|
|
|
|
08-14-2009, 12:26 PM
|
#3
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
A pipe works only where the command is expecting an input. ls does not expect an input, so it ignores what you are sending it.
|
|
|
|
08-14-2009, 01:05 PM
|
#4
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Another option is to use `xargs'. Since a name might contain white space, that needs to be taken into account.
find . -name FILENAME -print0 | xargs -0 ls -l
There is an "ls" command in find, so this would be easiest:
find . -name FILENAME -ls
|
|
|
|
08-14-2009, 11:48 PM
|
#5
|
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,780
|
Quote:
Originally Posted by pixellany
A pipe works only where the command is expecting an input. ls does not expect an input, so it ignores what you are sending it.
|
ls can use input (options, specific directory, specific file) so I doubt this is the reason it does not work
grep definitely needs input and it will also not work when it receives data piped from the find command
What am I missing from your post?
|
|
|
|
08-15-2009, 02:02 AM
|
#6
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Quote:
Originally Posted by Wim Sturkenboom
ls can use input (options, specific directory, specific file) so I doubt this is the reason it does not work
grep definitely needs input and it will also not work when it receives data piped from the find command
What am I missing from your post?
|
I don't think you missed anything---there is obviously something I don't understand.....
Are you saying you cannot pipe the output of find to **anything**?
If a command produces output, does it even know that it is being piped?
|
|
|
|
08-15-2009, 02:13 AM
|
#7
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Quote:
|
grep definitely needs input and it will also not work when it receives data piped from the find command
|
Works here......so does SED.
Trying to pipe something to ls: Tried echo <string>|ls---does not work.
I am beginning to think I might have been more right than wrong......
|
|
|
|
08-15-2009, 05:21 AM
|
#8
|
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,780
|
Below an old issue that I encountered long ago with find. Somebody suggested paulsm4's solution (post #2) to overcome the problem. That is why I'm wondering what is going on after reading your post.
Code:
[user@localhost Documents]$ cat abc.txt
hallo
hello
[user@localhost Documents]$ find . -name abc*
./abc.txt
[user@localhost Documents]$ find . -name abc* |grep hello
[user@localhost Documents]$ grep hello *
abc.txt:hello
[user@localhost Documents]$
PS. Taken from a Linpus Lite machine
|
|
|
|
08-15-2009, 06:53 AM
|
#9
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,367
|
Quote:
Originally Posted by Wim Sturkenboom
Below an old issue that I encountered long ago with find.
|
What's the issue? It's working as I'd expect unless I am the stick wrong end having.
|
|
|
|
08-15-2009, 08:17 AM
|
#10
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Code:
[user@localhost Documents]$ find . -name abc* |grep hello
grep is working on file names.
----
Code:
[user@localhost Documents]$ grep hello *
abc.txt:hello
grep is working on file contents.
Last edited by pixellany; 08-15-2009 at 08:21 AM.
|
|
|
|
08-15-2009, 08:20 AM
|
#11
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Quote:
Originally Posted by catkin
unless I am the stick wrong end having.
|
Yoda's version of the English translation of an Indian colloquialism??.... 
|
|
|
|
08-15-2009, 08:42 AM
|
#12
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,367
|
Quote:
Originally Posted by pixellany
Yoda's version of the English translation of an Indian colloquialism??.... 
|
Origins lost in history but the only suggested origin found that carries any sense of misunderstanding (as opposed to simply being disadvantaged) is in the last paragraph here about a botched Christening. Definitely from British English but surely both Lucas and the Rishis could develop it nicely. I hope this is not enough to have us banished to General 
|
|
|
|
08-16-2009, 01:38 AM
|
#13
|
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,780
|
pixellany, thanks
I think that the dime has finally fallen; it took about 10 years
The solution for me would have been
Code:
grep hello < `find . -name abc*`
hello
|
|
|
|
08-16-2009, 03:41 AM
|
#14
|
|
Member
Registered: Aug 2009
Distribution: slackware 12.2
Posts: 51
Rep:
|
xargs
probably the easiest would be using "xargs". xargs executes a command on every file in a list of file read from the standard input, thus input can be piped to it.
Code:
find /dir -name example.txt | xargs ls -l
this command looks for a file named "examples.txt" in the directory "/dir" and all its subdirectories recursivly. if it finds a file "examples.txt" it executes the command "ls -l" on it.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:29 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|