Skip to content
Advertisement

Piping to File Utility

I am being sent the bytes of thousands files over an interface, and my app must maintain statistics regarding the counts of various files types which it observes (text, HTML, binary, compressed, etc.). I have been using the subprocess module to run the file utility. However, as the scale has increased, I am having performance issues due to the IO time needed to write and read the bytes to the disk.

I would like to pipe the bytes directly to file to avoid the IO penalty. I have seen this before with grep such as ls -l | grep html. However, I can’t get echo "Hello, world" | file to work.

Advertisement

Answer

echo foo | file -

The dash stands for stdin.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement