Saturday, May 18, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 678  / 2 Years ago, wed, may 11, 2022, 7:08:18

I want to check if a hard disk drive has been successfully zeroed. I read this, which instructs to run:



$ sudo od /dev/disk2 | head


which for his HDD returns:



0000000    000000  000000  000000  000000  000000  000000  000000  000000
*
234250000


I've read here that




head returns the first ten lines of each file name that is provided
to it.





  1. Am I right in assuming that without | head, od will print the entire HDD contents to terminal?


  2. When I tried this, I got the same output: 1 seven-digit 0s and 8 six-digit 0s and 1 *, except that after the * I get 7216060060000. Is everything up to and including the * the ten "lines" (though this isn't a file and there shouldn't be any lines)?


  3. Why is only the first number seven digits?


  4. What does the * mean? Does it mean that everything else can be anything (not necessarily zeroes), are all zeroes (i.e. my whole HDD is all zeroes), or are all the same preceding pattern repeating (i.e. 1 seven-digit 0s and 8 six-digit 0s)?


  5. The od manpage states the od command will: "Write an unambiguous representation, octal bytes by default, of FILE to standard output." What is an "octal byte"? This suggests it is nonstandard terminology but might be 6 bits.


  6. My HDD is 500 GB with 512-byte sectors. Does this 7216060060000 equal that capacity?



    7216060060000 octal bytes * (6 bits? / 1 octal byte?) * (1 byte/8 bits) * (1 GB/1e9 bytes)
    = 5412.045045 GB



    which isn't my HDD capacity. Did something go wrong?


  7. Was my HDD successfully zeroed?



More From » command-line

 Answers
2

  1. No. head will cut off output after 10 lines by default. Since there were only three lines total in the output, you'll get only three lines with or without head.

  2. As for lines, why should only files have lines? Do you want all command output to be stuffed into one line?

  3. It's an octal number showing how many bytes have been read since the start of the input. It can be more digits if needed.

  4. From man od:



    -v, --output-duplicates
    do not use * to mark line suppression


    So od tries to avoid printing duplicate lines. * marks those.


  5. From the original od documentation (which is clearer):




    Each line of output consists of the offset in the input, followed by
    groups of data from the file. By default, od prints the offset in
    octal, and each group of file data is a C short int’s worth of input
    printed as a single octal number.




    So each block as a whole is an octal number. A C short int is usually 2 bytes. od takes two bytes worth of data, treats it as a number, and prints it in base 8 as a single number, and repeats. Each line has 8 such blocks, so we have 16 bytes per line. The offset is also printed in base 8, and 20 in base 8 is 16 in base 10.


  6. Since the offset is in base 8, converting to base 10:



    $ echo $((8#7216060060000))
    500107862016
    $ echo $((8#7216060060000 / 1000 / 1000 / 1000))
    500


    $((N#X)) tells bash to read X as a base-N number. Since bash outputs in base 10 by default, doing $((8#...)) converts from octal to decimal.


  7. Yes.



[#9991] Thursday, May 12, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
edseager

Total Points: 185
Total Questions: 105
Total Answers: 102

Location: Angola
Member since Wed, Apr 13, 2022
2 Years ago
;