Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I type something like:

find . -name *foo* | ls -lah

it returns the same result as a plain ls command, as though it had no input.


ls -lah $( find . -name *foo* )

works well, but only when the find command has results.

Is it possible to pipe to ls ?

share|improve this question
up vote 13 down vote accepted

You can use -exec with find command.

find . -name '*foo*' -exec ls -lah {} \;
share|improve this answer
Thank you for your solution. There is no pipe but it's an elegant method. If there aren't found any results with 'find' it doesn't display anything (what is in fact good). – Lasall May 21 '11 at 7:22
A slightly better way: find . -name '*foo*' -exec ls -lah {} + – jlliagre May 22 '11 at 3:35
find . -name *foo* | xargs -r ls -lah

That should work.

share|improve this answer
Thank you for that solution. But how can I deal with whitespaces? – Lasall May 21 '11 at 6:59
@Lasall the preferred way is to use find's -exec + (or -exec \;). xargs is only safe to use with the -0 option, which means that you have to tell whatever command you pipe to xargs to delimit the items with NULL-bytes (\0). With find you can do that with -print0. xargs's -0 and find's -print0 are not standard, but -exec is, so if portability is ever an issue, use find with -exec. – geirha May 26 '11 at 23:29
@geirha: Thank you for your exact explanation. – Lasall May 27 '11 at 14:06

Try this:

find  . -name *.bak -ls
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.