0

I would like to use the result of which ls and see the file type using file. However, when I type in which ls | file it doesn't work. When I try to do file < which ls, that doesn't work either.

Any pointers would be appreciated.

3
  • Use type -a ls instead. Which is not reliable to use for what you wanr Dec 19, 2022 at 7:24
  • @ValentinBajrami Thank you for trying to answer, but I was looking for the result of file /usr/bin/ls... Except, I would like to to check for which at the same time, and then use the result with file.
    – Grateful
    Dec 19, 2022 at 7:29
  • 1
    Does this answer your question? whereis, pipline and ls
    – muru
    Dec 19, 2022 at 7:43

1 Answer 1

2

This does not work because file takes the file to examine as commandline parameter (see man file).

You are piping the output of which to the stdin of the process executing ls.

What you should do is something like file "$(which ls)".

4
  • Aaaah... Perfect!
    – Grateful
    Dec 19, 2022 at 7:31
  • But then, why is it that I am able to do something like man ls | head... Although, head would also be expecting command line arguments ?
    – Grateful
    Dec 19, 2022 at 7:40
  • 2
    From man head: With no FILE, or when FILE is -, read standard input.. This means, that head takes stdin if no FILE is given.
    – gerhard d.
    Dec 19, 2022 at 7:55
  • Aaaah! That makes sense, thank you so much!!
    – Grateful
    Dec 19, 2022 at 8:17

You must log in to answer this question.

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