coreutils¶
dd¶
dd is a program that allows you to convert and copy a file.
It is most often used for low level operations on device files in a linux system.
Clarifying how the arguments work¶
Almost all arguments to dd are relative to the values of ibs/obs/bs.
All arguments except ibs/obs/bs are the number of "blocks", not the number of "bytes".
So when bs=4, then if count=4 then 16 bytes will be processed.
Reading arbitrary addresses / offsets with dd¶
ifile=/dev/mem
offset=0x00010000
ofile=/tmp/data.bin
word_size=4
words=1
dd if="$ifile" of="$ofile" bs="$word_size" count="$words" skip="$((offset / word_size))" &> /dev/null \
&& rev "$ofile" \
| xargs printf '%s\n'
Note
For little endian, you'd remove the rev command.
printf¶
printf format table¶
See man printf.3.
Or the wikipedia.
size_t and ssize_t¶
Use one of: %zd, %zu, %zx.
Warning
Microsoft compilers use different expressions.
Pointers¶
Use %p.
Tip
If you are printing pointers to memory in the Linux Kernel, you may want to convert to unsigned long long instead (particularly for FPGA addresses):
seq¶
Generate sequences in the shell.
Tip
In newer shells, like bash, you can use built in shell features to accomplish this.