How do I redirect output of command into ls?

ls does not take input from standard in, but only from arguments:

Try ls -l "$(which python3)"


ls does not read from the pipe. In fact, ls does not use its standard input at all.

Instead, you have to pass the thing you'd like to run ls -l on via the command line of ls:

ls -l "$( which python3 )"

This uses a command substitution on the command line of ls -l which will expand to the output of the which command. This will then be used as a command line argument for ls.

Alternatively:

ls -l "$( command -v python3 )"

Related:

  • Why not use "which"? What to use then?

Other answers are good, but this is also handy:

which python3 | xargs ls -l

xargs gets values from stdin and appends them as command-line argument to the specified program.

Tags:

Shell

Osx