this post was submitted on 20 Dec 2025
25 points (100.0% liked)
Linux
10710 readers
323 users here now
A community for everything relating to the GNU/Linux operating system (except the memes!)
Also, check out:
Original icon base courtesy of lewing@isc.tamu.edu and The GIMP
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
When you use the pipe you're passing stdout from the left command to stdin on the right command.
file takes a filename as an argument, it does not read stdin (by default).
The first command works because head does read from stdin and then echoes the first line, but as an argument to file using command substitution - the $( ... ) bit. Command substitution is neat but this is not really the best use-case for it.
A better way is to use find with -print0 which makes it use a zero-byte instead of a newline character (otherwise the command will fail in case a filename contains a newline - newlines and spaces in filenames break a lot of scripts if you aren't careful) and -quit, which makes find exit after the first match. And then pass it to xargs which is a utility that transfers stdin to command arguments - In this case the file binary - and handles zero-bytes as seperators when using the -0 arg.
$ find /usr/lib -maxdepth 1 -type l -print0 -quit | xargs -0 fileRemoving -quit from the find command also works as expected (ie. on each found link).
Thanks! So this was more about my lack of understanding of how the file command works... But anyway, this gave me some new stuff to study! Especially the -print0 and -quit options and the xargs command.