Super User is a question and answer site for computer enthusiasts and power users. 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

I would like to

  1. find specific folders
  2. echo their name
  3. ls -l their contents

My problem is that I don't know how to combine an echo {} and an ls -l {} in one find command.

line for echo:

sudo find / -type d -name 'yt' -exec echo {} \;

line for ls:

sudo find / -type d -name 'yt' -exec ls -l {} \;

How can I combine these two?

note: I prefer not to use xargs if possible, as it has problems with escaping filenames properly.

share|improve this question
up vote 1 down vote accepted

Why not just put two different -exec options in the same find command?

This works for me:

$ find --version
find (GNU findutils) 4.4.2
$ find . -type d -name mydir -exec echo {} \; -exec ls -l {} \;
total 0
-rw-rw-r-- 1 daniel daniel 0 févr. 25 15:32 myfile
share|improve this answer
thanks, i didn't know it's possible – zsero Feb 25 '14 at 15:11

This is not generic solution but will work for you since you search for directories:

sudo find / -type d -name 'yt' -execdir readlink -f {} \; -exec ls -l {} \;

The execdir executes a command on the subdirectory matching the found file (which, since you search for the directories) is the directory itself (and readlink -f gives it's full path). The second -exec will on the other side match the directory again and do the "ls -" on them.

Using jsut echo on the first execdir wouldn't write you the full path but just the last directory which may not be enough.

share|improve this answer

You can use the print command here easily.

$sudo find / -type d -name 'bin' -print  -exec ls -l {} \;

For example,

  1. find bin folders
  2. echo their name or print their names
  3. ls -l their contents - list their contents.
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .