MrBrightside
MrBrightside

Reputation: 623

pipe a command after splitting the returned value

I'm using a find command which results in multiple lines for result, I then want to pipe each of those lines into an ls command with the-l option specified.

find . -maxdepth 2  -type f |<some splitting method> | ls -l

I want to do this in one "command" and avoid writing to a file.

Upvotes: 2

Views: 81

Answers (3)

sampson-chen
sampson-chen

Reputation: 47267

I believe this is what you are looking for:

find . -maxdepth 2  -type f -exec ls -l {} \;

Explanation:

  • find . -maxdepth 2 -type f: find files with maxdepth at 2
  • -exec ls -l {} \; For each such result found, run ls -l on it; {} specifies where the results from find would be substituted into.

Upvotes: 2

wjl
wjl

Reputation: 7755

Sounds like you are looking for xargs. For example, on a typical Linux system:

find . -maxdepth 2  -type f -print0 | xargs -0 -n1 ls -l

Upvotes: 0

William Pursell
William Pursell

Reputation: 212238

The typical approach is to use -exec:

find . -maxdepth 2  -type f -exec ls -l {} \;

Upvotes: 1

Related Questions