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?
|
Here's one option:
Quote:
|
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.
|
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 |
Quote:
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? |
Quote:
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? |
Quote:
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...... |
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 |
Quote:
|
Code:
[user@localhost Documents]$ find . -name abc* |grep hello ---- Code:
[user@localhost Documents]$ grep hello * |
Quote:
|
Quote:
|
pixellany, thanks
I think that the dime has finally fallen; it took about 10 years :o The solution for me would have been Code:
grep hello < `find . -name abc*` |
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 |
All times are GMT -5. The time now is 08:22 PM. |