Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
3
votes
0
answers
63
views
How to display a UTF8 encoded text file as a hex dump but with the characters in the right column
This is the sample.txt Greek in UTF8: ανθρώπους. Από ανθρώπους. Από When I run the command below I get the hex output but not the corresponding characters in the right column but instead I see ......... $ xxd -l 120 -c 12 sample.txt 00000000: ceb1 cebd ceb8 cf81 cf8e cf80 ............ 0000000c: cebf...
This is the sample.txt Greek in UTF8:
ανθρώπους.
Από
ανθρώπους.
Από
When I run the command below I get the hex output but not the corresponding characters in the right column but instead I see .........
$ xxd -l 120 -c 12 sample.txt
00000000: ceb1 cebd ceb8 cf81 cf8e cf80 ............
0000000c: cebf cf85 cf82 2e0a ce91 cf80 ............
00000018: cf8c 0ace b1ce bdce b8cf 81cf ............
00000024: 8ecf 80ce bfcf 85cf 822e 0ace ............
00000030: 91cf 80cf 8c0a
I m looking for a way to show the actual characters as well.
user603749
(131 rep)
Mar 26, 2025, 06:29 PM
• Last activity: Mar 26, 2025, 08:10 PM
0
votes
0
answers
49
views
Hexdump prints beyond EOF with format string
I am in the process of writing a `xxd -i` like script. For that I need the hex dump of a file. I am using the following command for that: `hexdump -v -e '8/1 "0x%02x," "\n"'` this works fine when the amount of bytes is divisible by 8: `0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,` However, when the amou...
I am in the process of writing a
xxd -i
like script.
For that I need the hex dump of a file.
I am using the following command for that:
hexdump -v -e '8/1 "0x%02x," "\n"'
this works fine when the amount of bytes is divisible by 8:
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,
However, when the amount of bytes is not divisible by 8, it still formats non-existing bytes:
0x89,0x50,0x4e,0x47,0x ,0x ,0x ,0x ,
Is it either possible to zero-fill the bytes (i.e. make hexdump report null-bytes after eof) or simply "cancel" the formatting after the last real byte?
Raildex
(101 rep)
Mar 6, 2025, 08:57 PM
13
votes
3
answers
14775
views
What is the difference between the od, hd, hexdump and xxd commands?
What is the difference between the od, hd, hexdump and xxd commands ? They are all commands for dumping files and they can all dump it in various formats such as hexadecimal, octal or binary. Why creating different programs ?
What is the difference between the od, hd, hexdump and xxd commands ?
They are all commands for dumping files and they can all dump it in various formats such as hexadecimal, octal or binary. Why creating different programs ?
Nicryc
(335 rep)
Jan 15, 2020, 10:47 PM
• Last activity: Jan 9, 2025, 02:25 PM
0
votes
1
answers
590
views
Shift the address in the hex file with Offset
I want to update the hexfile start address with offset. For example, i have a hex file name **abc.hex** and start with address 0x0000 to 0xFFFF. But I want to shift the context in the hexfile to the address 0x1FFFF. How Can we do this in linux with tool like hexdump or xxd?
I want to update the hexfile start address with offset. For example, i have a hex file name **abc.hex** and start with address 0x0000 to 0xFFFF. But I want to shift the context in the hexfile to the address 0x1FFFF.
How Can we do this in linux with tool like hexdump or xxd?
sagar
(3 rep)
Sep 5, 2023, 08:27 AM
• Last activity: May 29, 2024, 11:04 AM
1
votes
1
answers
75
views
CPIO Archive Hexdump on a Big-Endian Linux Machine
I'm on a little-endian linux machine and would like to see the canoncial hexdump of a cpio archive on big-endian linux machine. Can someone please run these commands on a big-endian linux and post the output: echo TESTING > /tmp/test cpio -o /tmp/test.cpio hexdump -C /tmp/test.cpio If you are curiou...
I'm on a little-endian linux machine and would like to see the canoncial hexdump of a cpio archive on big-endian linux machine.
Can someone please run these commands on a big-endian linux and post the output:
echo TESTING > /tmp/test
cpio -o /tmp/test.cpio
hexdump -C /tmp/test.cpio
If you are curious, I need this because libmagic does the following to determine the cpio archive type:
# same byteorder machine
0 short 070707
26 string >\0 cpio archive
# opposite byteorder machine
0 short 0143561 byte-swapped cpio archive
I want to see if there's a reason libmagic doesn't check 26th byte of the archive for the opposite byteorder machine.
The output of the command on my little-endian machine:
1 block
00000000 c7 71 1b 00 57 01 a4 81 e8 03 e8 03 01 00 00 00 |.q..W...........|
00000010 ff 65 ce a4 0a 00 00 00 08 00 2f 74 6d 70 2f 74 |.e......../tmp/t|
00000020 65 73 74 00 54 45 53 54 49 4e 47 0a c7 71 00 00 |est.TESTING..q..|
00000030 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 |................|
00000040 0b 00 00 00 00 00 54 52 41 49 4c 45 52 21 21 21 |......TRAILER!!!|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000200
Arash Rohani
(130 rep)
Mar 24, 2024, 04:09 AM
• Last activity: Mar 26, 2024, 02:58 AM
12
votes
4
answers
17219
views
Get hex-only output from objdump
Say for example I've got this C function: void f(int *x, int *y) { (*x) = (*x) * (*y); } When saved to `f.c`, compiling with `gcc -c f.c` produces `f.o`. `objdump -d f.o` gives this: f.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 : 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%...
Say for example I've got this C function:
void f(int *x, int *y)
{
(*x) = (*x) * (*y);
}
When saved to
f.c
, compiling with gcc -c f.c
produces f.o
. objdump -d f.o
gives this:
f.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 :
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 89 7d f8 mov %rdi,-0x8(%rbp)
8: 48 89 75 f0 mov %rsi,-0x10(%rbp)
c: 48 8b 45 f8 mov -0x8(%rbp),%rax
10: 8b 10 mov (%rax),%edx
12: 48 8b 45 f0 mov -0x10(%rbp),%rax
16: 8b 00 mov (%rax),%eax
18: 0f af d0 imul %eax,%edx
1b: 48 8b 45 f8 mov -0x8(%rbp),%rax
1f: 89 10 mov %edx,(%rax)
21: 5d pop %rbp
22: c3 retq
I'd like it to output something more like this:
55 48 89 e5 48 89 7d f8 48 89 75 f0 48 8b 45 f8 8b 10 48 8b 45 f0 8b 00 0f af d0 48 8b 45 f8 89 10 5d c3
I.e., just the hexadecimal values of the function. Is there some objdump
flag to do this? Otherwise, what tools can I use (e.g. awk, sed, cut, etc) to get this desired output?
MD XF
(241 rep)
Feb 3, 2018, 12:30 AM
• Last activity: May 29, 2023, 07:28 PM
2
votes
0
answers
113
views
Should programs terminate on ENOSPC error?
In bash, the command `hexdump -C /dev/urandom > hexdump.txt` does not terminate. It keeps going indefinitely, even if the filesystem is full. read(0, "\326\210L0\rL .%."..., 4096) = -1 ENOSPC (No space left on device) read(0, "\336&v\266I\10\254\3551\225\370\"^g\224\10\5\17h\tNkA.(\374\302\333`K/\33...
In bash, the command
hexdump -C /dev/urandom > hexdump.txt
does not terminate.
It keeps going indefinitely, even if the filesystem is full.
read(0, "\326\210L0\rL.%."..., 4096) = -1 ENOSPC (No space left on device)
read(0, "\336&v\266I\10\254\3551\225\370\"^g\224\10\5\17h\tNkA.(\374\302\333`K/\332"..., 4096) = 4096
write(1, " ad 7a 3f 0c f4 0e a0 b8 8d |."..., 4096) = -1 ENOSPC (No space left on device)
write(1, "ab 1c f4 79 f1 49 20 0e a1 f3 7"..., 4096) = -1 ENOSPC (No space left on device)
In the event that it does terminate (when the input is not infinite) it still reports a write error at the very end... but by that point it has consumed the input entirely, producing countless ENOSPC errors.
Then I tested other commands. busybox hexdump
has the same issue. od
has the same issue. strings
has the same issue...
So this involves util-linux, coreutils, binutils, ...?
I can work around the issue like hexdump -C /dev/urandom | cat > hexdump.txt
this works since cat
, dd
, pv
terminates on write error, which in turn kills the entire pipe. But it looks so weird.
Is this a bug across the board or is there some standard that requires these utils must consume all inputs?
user566667
Apr 24, 2023, 07:57 PM
1
votes
1
answers
447
views
Unix ext2 superblock - file system creation date
I am trying to find the creation date on an _ext2_ file system. I seem to get a current date using `dumpe2fs`. The problem is that the original _ext2_ superblock specification does not contain such information, though it seems like there might be an extension to the original fields (something about...
I am trying to find the creation date on an _ext2_ file system. I seem to get a current date using
The problem is that the original _ext2_ superblock specification does not contain such information, though it seems like there might be an extension to the original fields (something about after byte 264).
In fact using
Thanks in advance
dumpe2fs
.The problem is that the original _ext2_ superblock specification does not contain such information, though it seems like there might be an extension to the original fields (something about after byte 264).
In fact using
hexdump
on the superblock (hexdump -s 1024 -n 1024 -C /dev/vdb
) I can find 4 bytes starting from byte _265_ that containg a hex number which contain in little endian the unix time of the file system creation. Any information on how, why and under what circumstances that it there?Thanks in advance
Panagiotis Stefanis
(13 rep)
Jan 12, 2023, 06:01 PM
• Last activity: Jan 12, 2023, 11:03 PM
0
votes
2
answers
772
views
read raw data from disk and convert
please help to find a way to convert the data as follows: I read from disk using dd utility > dd if=/dev/sdb skip=8388608 count=560 iflag=skip_bytes,count_bytes |hexdump -C and I am getting > 000001a0 00 00 00 00 cf 4c 79 ce 00 00 00 00 00 00 00 00 |.....Ly.........| but I would like to get : > 0000...
please help to find a way to convert the data as follows:
I read from disk using dd utility
> dd if=/dev/sdb skip=8388608 count=560 iflag=skip_bytes,count_bytes |hexdump -C
and I am getting
> 000001a0 00 00 00 00 cf 4c 79 ce 00 00 00 00 00 00 00 00 |.....Ly.........|
but I would like to get :
> 000001a0 ce794ccf00000000 0000000000000000 |.....Ly.........|
I do not have to use hexdump, any other tool can also do the trick. Thank you.
markmi
(1 rep)
Feb 10, 2022, 07:51 AM
• Last activity: Dec 21, 2022, 12:42 PM
7
votes
1
answers
76196
views
How to convert hexdump to text?
I know that `xxd` is used to convert texts to hexdump but I want to do the opposite: convert an hex dump to text! Is there some command that I can use? Thanks for the help!
I know that
xxd
is used to convert texts to hexdump but I want to do the opposite: convert an hex dump to text! Is there some command that I can use? Thanks for the help!
Pichi Wuana
(1459 rep)
Aug 29, 2016, 09:10 PM
• Last activity: Dec 14, 2022, 02:42 PM
1
votes
0
answers
261
views
Iterative hexdump to find a value
As you can see the output of a hexdump command. I would like to iterate throughout the hard disk (or some limit) in order to find a value as a `while-loop`, in example `APSB` value. The step are in my case is `4096` bytes 1. Iteration 1: `hexdump -n 4096 -Cv /dev/disk0s1 -s 0` 2. Iteration 2: `hexdu...
As you can see the output of a hexdump command. I would like to iterate throughout the hard disk (or some limit) in order to find a value as a
while-loop
, in example APSB
value.
The step are in my case is 4096
bytes
1. Iteration 1: hexdump -n 4096 -Cv /dev/disk0s1 -s 0
2. Iteration 2: hexdump -n 4096 -Cv /dev/disk0s1 -s 4096
3. Iteration 3: hexdump -n 4096 -Cv /dev/disk0s1 -s 9192
Here a related question of How I thought the previous iteration.
But, how to find a value inside the hexdump
output?
Is it possible?
sh-3.2# hexdump -n 4096 -Cv /dev/disk0s1 -s 0
00000000 8d 1c 09 48 65 8c 3c 6e 01 00 00 00 00 00 00 00 |...He...@}>y........|
00000060 be 04 00 00 00 00 00 00 10 00 00 00 84 04 00 00 |................|
00000070 01 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 |................|
00000080 0a 00 00 00 e2 00 00 00 00 00 00 00 00 00 00 00 |................|
00000090 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 |................|
000000a0 34 1e 00 00 00 00 00 00 01 04 00 00 00 00 00 00 |4...............|
000000b0 00 00 00 00 04 00 00 00 02 04 00 00 00 00 00 00 |................|
000000c0 06 04 00 00 00 00 00 00 08 04 00 00 00 00 00 00 |................|
000000d0 0a 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
Thanks in advance...
joseluisbz
(375 rep)
Aug 13, 2022, 09:11 PM
• Last activity: Aug 15, 2022, 06:03 AM
0
votes
0
answers
193
views
How to recreate wildcard lines from `hexdump` output?
I have a problem: I have some old `hexdump`s laying around as text files. I want to recreate the files they represent because I'm interested in what these files were. The problem is: When I created these `hexdump`s I didn't know of the `-v` flag, so in some of the `hexdump`s some repeating lines are...
I have a problem: I have some old
hexdump
s laying around as text files.
I want to recreate the files they represent because I'm interested in what these files were.
The problem is: When I created these hexdump
s I didn't know of the -v
flag, so in some of the hexdump
s some repeating lines are replaced with a *
.
What I want is a way to programmatically recreate those lines using bash
or python3
.
I also have a concept no how to do it but I didn't manage to create a working script to recreate those lines.
My concept is:
1. Check the file for lines which are made up of only a *
. (if there are none, jump to step 6)
2. Loop through the found lines:
3. Calculate the amount of lines that were replaced with that asterisk, by taking the offset numbers.
4. Copy the line above the asterisk the calculated amount of times and thereby replace the asterisk.
5. If there are asterisks left: repeat steps 3 and 4 for the next asterisk, otherwise do step 6:
6. Print out the completed hexdump.
##### Question:
Can someone please help me to create a script that does the above? Or a script that gives the same end result but works better?
Lampe2020
(115 rep)
Jul 1, 2022, 01:02 PM
• Last activity: Jul 1, 2022, 01:10 PM
4
votes
2
answers
2965
views
How to format hexdump as xxd, possible for xxd -revert?
I wish to dump the raw content of a SD card into a file for inspection. Most parts of it are zeroes. Learnt from [this SuperUser answer][1] I could use `pv` to show the progress of `od` and `hexdump`. Both ETA are 1.5 hours. # pv /dev/sdd | od -x --endian=big > sdd_file ... ... ... [> ] ... ETA 1:34...
I wish to dump the raw content of a SD card into a file for inspection. Most parts of it are zeroes. Learnt from this SuperUser answer I could use
pv
to show the progress of od
and hexdump
. Both ETA are 1.5 hours.
# pv /dev/sdd | od -x --endian=big > sdd_file
... ... ... [> ] ... ETA 1:34:42
and
# pv /dev/sdd | hexdump -C > sdd_file
... ... ... [> ] ... ETA 1:35:01
However xxd
would need 11 hours.
# pv /dev/sdd | xxd -a -u > sdd_file
... ... ... [> ] ... ETA 10:48:53
I prefer xxd
mostly because of the -revert
possibility. But xxd
would take way too long to process a disk. How to format hexdump
(or od
) to produce the same file format as xxd
, so that the file is possible to be -reverted
by xxd
?
midnite
(613 rep)
Dec 18, 2021, 06:59 PM
• Last activity: Jun 29, 2022, 12:33 PM
2
votes
2
answers
792
views
Have hexdump do print a line everytime the Ascii 0a reached
as `$ hexdump -C data` print the hex content of file in 16 bytes a line How then to, by set its option, to print a line everytime the Ascii 0a (newline) is encountered ?
as
$ hexdump -C data
print the hex content of file in 16 bytes a line
How then to, by set its option, to print a line everytime the Ascii 0a (newline) is encountered ?
user496281
Oct 15, 2021, 04:37 AM
• Last activity: Oct 20, 2021, 08:06 AM
0
votes
2
answers
352
views
Grub bootup steps
Am installing gentoo. At Grub bootloader but can’t seem to find kernel, which is odd because it’s existence was verified before restarting the machine. There doesn’t seem to be a “root” or “kernel” command, nor “vmlinuz”. Hexdumping gpt1 and gpt2 (the only two partitions with recognizable file syste...
Am installing gentoo. At Grub bootloader but can’t seem to find kernel, which is odd because it’s existence was verified before restarting the machine. There doesn’t seem to be a “root” or “kernel” command, nor “vmlinuz”. Hexdumping gpt1 and gpt2 (the only two partitions with recognizable file systems to grub) says they’re not bootable disks.
Edit: Made some progress—found the vmlinuz and initramfs with “ls (hd0, partition)/“. Used “linux” command and initrd to set and handle boot. Used “boot” to boot. Oddly enough, the partition with the correct filesystem for boot seems to require a rescue shell.
Here are the instructions I’m following: https://christitus.com/grub-rescue/
Linuxn00b
(11 rep)
Aug 23, 2021, 03:41 AM
• Last activity: Aug 29, 2021, 11:10 AM
43
votes
7
answers
28733
views
Is there an alternative to sed that supports unicode?
For example: sed 's/\u0091//g' file1 Right now, I have to do `hexdump` to get hex number and put into `sed` as follows: $ echo -ne '\u9991' | hexdump -C 00000000 e9 a6 91 |...| 00000003 And then: $ sed 's/\xe9\xa6\x91//g' file1
For example:
sed 's/\u0091//g' file1
Right now, I have to do
hexdump
to get hex number and put into sed
as follows:
$ echo -ne '\u9991' | hexdump -C
00000000 e9 a6 91 |...|
00000003
And then:
$ sed 's/\xe9\xa6\x91//g' file1
A-letubby
(709 rep)
Apr 17, 2015, 08:38 AM
• Last activity: Jun 21, 2021, 09:54 PM
3
votes
1
answers
657
views
Bad byte count while using hexdump
I am trying to display a binary file with records consisting of: 8 bytes unsigned int 4 bytes unsigned int 4 bytes unsigned int 4 bytes unsigned int 4 bytes unsigned int I try to display it using `hexdump` as follows: hexdump -v -e '1/8 "%015d " 4/4 " %6d" "\n"' binfile But I get: hexdump: d: bad by...
I am trying to display a binary file with records consisting of:
8 bytes unsigned int
4 bytes unsigned int
4 bytes unsigned int
4 bytes unsigned int
4 bytes unsigned int
I try to display it using
hexdump
as follows:
hexdump -v -e '1/8 "%015d " 4/4 " %6d" "\n"' binfile
But I get:
hexdump: d: bad byte count
I am using FreeBSD 12 -if relevant-
M.E.
(631 rep)
Jun 1, 2021, 09:24 AM
• Last activity: Jun 1, 2021, 10:26 AM
1
votes
1
answers
2707
views
How to jump X bytes down in hexedit?
I am looking through a memory dump B79C6440 64 6F 6E 65 00 00 6C 5F 75 62 6C 65 20 73 68 6F done..l_uble sho B79C6450 77 5F 00 00 5F 6F 6E 5F 72 75 70 00 00 61 63 6B w_.._on_rup..ack B79C6460 69 72 71 5F 76 65 63 74 6F 72 73 10 10 05 30 10 irq_vectors...0. B79C6470 06 50 10 07 70 10 08 90 10 09 B0 1...
I am looking through a memory dump
B79C6440 64 6F 6E 65 00 00 6C 5F 75 62 6C 65 20 73 68 6F done..l_uble sho
B79C6450 77 5F 00 00 5F 6F 6E 5F 72 75 70 00 00 61 63 6B w_.._on_rup..ack
B79C6460 69 72 71 5F 76 65 63 74 6F 72 73 10 10 05 30 10 irq_vectors...0.
B79C6470 06 50 10 07 70 10 08 90 10 09 B0 10 0A 98 1B FC .P..p...........
B79C6480 16 9C 1B A0 A4 A8 18 6E 6D 69 5F 63 68 65 63 6B .......nmi_check
using Hexedit I can jump to a new address by pressing enter and typing the address in.
Say I want to move from address
B79C6440
by adding an offset of X bytes , how could I compute the new address I want to reach so I could type it in?
Three Diag
(507 rep)
May 1, 2021, 04:23 PM
• Last activity: May 1, 2021, 06:02 PM
6
votes
1
answers
3521
views
What do these numbers in a 'hexdump' of a file mean?
I created a simple file, *1.txt*: echo "hello" >> 1.txt Then I dumped it: hexdump 1.txt And the terminal output: 0000000 68 65 6c 6c 6f 0a 0000006 What do `0000000` and `0000006` mean?
I created a simple file, *1.txt*:
echo "hello" >> 1.txt
Then I dumped it:
hexdump 1.txt
And the terminal output:
0000000 68 65 6c 6c 6f 0a
0000006
What do
0000000
and 0000006
mean?
ArchiT3K
(597 rep)
Sep 30, 2015, 10:52 AM
• Last activity: Apr 20, 2021, 07:49 PM
2
votes
2
answers
4344
views
Get absolute memory addresses instead of relative offsets from hexdump
I'm trying to get a better understanding of memory addresses. I've just begun examining binaries with `hexdump.` Ex output: ``` 0000000 cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00 0000010 0e 00 00 00 b0 03 00 00 85 00 00 00 00 00 00 00 0000020 19 00 00 00 48 00 00 00 5f 5f 50 41 47 45 5a 45 0000...
I'm trying to get a better understanding of memory addresses. I've just begun examining binaries with
hexdump.
Ex output:
0000000 cf fa ed fe 07 00 00 01 03 00 00 80 02 00 00 00
0000010 0e 00 00 00 b0 03 00 00 85 00 00 00 00 00 00 00
0000020 19 00 00 00 48 00 00 00 5f 5f 50 41 47 45 5a 45
0000030 52 4f 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000040 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00
My understanding is that the codes I see at the beginning of each line are relative memory addresses expressed as an offset from a base address. I'm trying to figure out if there's a way I can get the absolute addresses instead.
I'd be happy with a solution that either shows me those addresses explicitly, or simply helps me figure out what the base address is that they are relative to, so I can calculate them myself.
David Kennell
(185 rep)
Apr 26, 2019, 02:49 PM
• Last activity: Mar 24, 2021, 06:39 PM
Showing page 1 of 20 total questions