主页 Swift UNIX C Assembly Go Plan 9 Web MCU Research Non-Tech

How to check disk in hexadecimal by bytes in terminal on Mac or Linux

2023-07-05 | UNIX | #Words: 546

Before start to introduce, something be emphasized: This method does not guarantee to view all hard disks. Some hard disks will display “Resource busy” due to some reasons, such as Time Machine and built-in hard disks.

Supplies:

  1. Mac;
  2. Program hexdump
  3. Program dd

We will use dd to dump the content of disk, and we can view something:

$ sudo dd if=/dev/disk4 count=100000 | hexdump -C > disk.txt

Here are some explanations:

  1. You must use sudo to obtain permissions, otherwise you cannot open hard disk file in /dev/. This is different from some Linux distributions.
  2. dd is a program that is often used to copy hard disks and systems in byte format, so we can use it to output.
  3. if=/dev/disk4 is the path of the input file, and /dev/disk4 here is the hard disk we want to view. Notice: It must be a hard disk, not a partition. If you can’t distinguish this, then please read my other blog “How to use terminal commands to mount and uninstall an external hard drive in macOS (exploration of the use of diskutil command and APFS format)”’s “Extended Knowledge” section.
  4. count=100000 means outputting 100000 blocks. If you just want to see some information about the file system, then only using 1000 is almost enough.
  5. After output, we will use hexdump -C to read it. hexdump is a program for viewing files in hexadecimal on the terminal. -C will display the corresponding characters on the right side.
  6. ` > disk.txt will output a file named disk.txt` to view conveniently.
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 fe  |...............�|
000001c0  ff ff ee fe ff ff 01 00  00 00 fe ff ff ff 00 00  |������....����..|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U�|
00000200  45 46 49 20 50 41 52 54  00 00 01 00 5c 00 00 00  |EFI PART....\...|
00000210  15 51 0f ff 00 00 00 00  01 00 00 00 00 00 00 00  |.Q.�............|
00000220  ff ff bf 46 07 00 00 00  22 00 00 00 00 00 00 00  |���F....".......|
00000230  de ff bf 46 07 00 00 00  84 ec 00 4a 8e 8c fd 47  |���F.....�.J..�G|
00000240  8a 78 25 48 bf a4 90 99  02 00 00 00 00 00 00 00  |.x%H��..........|
00000250  80 00 00 00 80 00 00 00  98 27 08 16 00 00 00 00  |.........'......|
00000260  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

Other systems also can use this method, the difference is the path of disk devices. In Linux, it is in /mnt/ usually.

I hope these will help someone in need~