I was trying to find all symbolic links in /usr/lib and use file on the first entry in the list, which I delimited with head -n 1.

Why does find /usr/lib -maxdepth 1 -type l | file $(head -n 1) work but find /usr/lib -maxdepth 1 -type l | head -n 1 | file does not?

It complains that I am not using file correctly. Probably because it lacks an argument, but - programmatically/syntactically - why can’t file grab it’s argument from the pipe?

  • Christian L. (Sisko)@franken.social
    link
    fedilink
    arrow-up
    6
    ·
    15 hours ago

    @emotional_soup_88
    You could use “-” as argument for file:

    find /usr/lib -maxdepth 1 -type l | head -n 1 | file -

    which means, ‘file’ will read its input from the pipe. But that is probably not what you want, because ‘file’ parses the input and does not accept it as an argument.

    You use a pipe to pass the output of a program to another program, in order to do something with that input. Like:

    cat unsorted_list.txt | sort -

    • emotional_soup_88@programming.devOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      15 hours ago

      Thanks! I actually did try that, at which point it said “/dev/stdin ASCII text” or the likes, so it’s like the file command literally read the stdin device. Which was extremely intriguing, but not what I wanted. God, I love Linux :D

      • frongt@lemmy.zip
        link
        fedilink
        arrow-up
        4
        ·
        15 hours ago

        It’s not like it, it’s exactly it. The output from find is text, - means read stdin, so file told you the text in stdin was text. You’ll have to see if it takes a list of files as an option, otherwise just use a for loop.