Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 418  / 2 Years ago, tue, march 22, 2022, 4:01:56

We can truncate a big file to a size we want. For example, if I want to truncate a file to 1K byte, we can do truncate -s 1K file1. But this changes the original file file1.

Many times I want to see a beginning part of a big binary file. To open it with vi and then converting to hex-ascii format (using !%xxd in vi) takes too long. Of course I can copy the original file into another one and truncate the new file and open it with vi. But is there any way I can just extract from the beginning of a file an amount of bytes I want into another file so that I can open the smaller file to examine the beginning data of the original file?


More From » files

 Answers
4

head can do the trick as in:


head -c 1000 bigfile

would display the first 1000 bytes.


A construct as


head -c 1000 bigfile | vi -

would open this in vi.


[#2649] Wednesday, March 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breadoules

Total Points: 212
Total Questions: 118
Total Answers: 120

Location: Dominica
Member since Mon, Jun 22, 2020
4 Years ago
;