11

Is it possible to follow a binary file from the beginning, a la tail -f?

This is useful in some cases, for example if I'm scping a file to a remote server, and at the same time I want to feed it to another process (yes, I know I can use ssh+cat tricks).

As far as I read from the FM, tail is written having text files in mind.

Is there any simple way of doing such operations using standard posix tools?

2
  • Where does it say that tail can only be used with text files? Nov 28, 2011 at 15:34
  • @rozcietrzewiacz On older unices, text-oriented utilities such as tail didn't always cope with binary files: they might choke on null bytes or omit stray bytes after the last newline in the input files. Modern systems do cope. Nov 28, 2011 at 17:23

1 Answer 1

12

tail works with binary data just as well as with text. If you want to start at the very beginning of the file, you can use tail -c +1 -f.

1
  • Is this not working for anyone? I have a binary file that has 16 occurrences of a string that I see when I use cat bin_file | strings - -o | grep match_string, but when I do tail -c +1 -f bin_file | strings - -o | grep match_string, I get nothing past the 9th match. I also noted that the line numbers from -o are all 1 less compared to the cat output. If I leave the grep off, I get all 16 matches (mixed in with everything else), so I thought the problem was grep, but I tried a perl one-liner and it stops in the same place...
    – hepcat72
    May 17, 2019 at 19:23

You must log in to answer this question.

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