Search code examples
linuxfileshellhexdump

How to use hexdump to show charaters in different presentations at the same time


I am counting the number of characters of files and directory names of an entire directory.

find . -printf "%f/n" | sed 's/./&\n/g' | sort | uniq -c 

Output:

    234 _
    162 /
    341 .
    342 0
    156 1
    217 2
     99 3
    ...

But I need also a list of decimal, hex and normal representation at the same time of the found characters:

Example:

066 0x42 'A'
...
090 0x5A 'Z' 

I have tried hexdump with different format options but this didn't work for me.

Can it be done with hexdump ?


Solution

  • Can it be done with hexdump?

    Yes:

    find . -printf "%f/n" |
    hexdump -v -e '/1 "%03d "' -e '/1 "0x%02X "' -e '/1 "%c\n"'
    

    See examples at the end of the hexdump man page.