I was reading this thread. The command tail -c +K /tmp/1 outputs bytes starting with the Kth of each file. From man tail

   -c, --bytes=K
          output the last K bytes; alternatively,  use  -c  +K  to  output
          bytes starting with the Kth of each file

I would like to find any tool which does this reverse i.e. start to read from the end of the file and read to the beginning of the file.

How can you do the reverse of tail -c +K?

  • You do say "start to read from the end … to the beginning …". – Do you mean that all the data is reversed? -ie. abc\n becomes \ncba
    – Peter.O
    Jul 16 '15 at 12:47
  • No possibility to reverse the data. You can assume the data size is 1 TB. On the other hard, when you read in reverse direction, the data seems to be reversed. So yes, the data should be read as \ncba... Jul 16 '15 at 13:00

With GNU head, you can use:

head -c K

to output the first K bytes of file.

head -c -0 file

also output all bytes in file but doesn't read from the end to the beginning.

  • Why head -c -0 file and not just cat file?
    – petry
    Jul 16 '15 at 10:50
  • 2
    @petry: It will help the OP to gain the whole picture about that head can do all the reverse of tailf he asked.
    – cuonglm
    Jul 16 '15 at 10:54
  • This returns the data in the normal reading direction. I file abc\n. It reads abc\n. It reads from the start of the file until the specific mark. I want from the specific mark to the start of the file. Jul 16 '15 at 13:05
  • @Masi: If the original data is 1234ABCD, then tail -c +4 outputs 4ABCD ... and head -c -3 outputs 1234A -- Is this what you want?
    – Peter.O
    Jul 16 '15 at 13:39
  • @Peter.O Otherwise head -c -3 is ok but everything should read from the reverse direction like A4321. To actually reverse the data and then just read can be too expensive process. To just read in reverse direction is wanted. Jul 16 '15 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.