1

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?

2
  • 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
    Commented Jul 16, 2015 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... Commented Jul 16, 2015 at 13:00

1 Answer 1

1

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.

5
  • Why head -c -0 file and not just cat file?
    – petry
    Commented Jul 16, 2015 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
    Commented Jul 16, 2015 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. Commented Jul 16, 2015 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
    Commented Jul 16, 2015 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. Commented Jul 16, 2015 at 14:27

You must log in to answer this question.

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