How to view files in binary from bash?

后端 未结 12 1907
北恋
北恋 2020-11-29 14:39

I would like to view the contents of a file in the current directory, but in binary from the command line. How can I achieve this?

相关标签:
12条回答
  • 2020-11-29 15:09
    hexdump -C yourfile.bin
    

    unless you want to edit it of course. Most linux distros have hexdump by default (but obviously not all).

    0 讨论(0)
  • 2020-11-29 15:09

    You can open emacs (in terminal mode, using emacs -nw for instance), and then use Hexl mode: M-x hexl-mode.

    https://www.gnu.org/software/emacs/manual/html_node/emacs/Editing-Binary-Files.html

    0 讨论(0)
  • 2020-11-29 15:09

    to convert a file to its binary codes(hexadecimal representation) we say:

    xxd filename                                         #
    

    e.g:

    xxd hello.c                                          #
    

    to see all the contents and codes in a binary file , we could use commands like readelf and objdump, hexdump ,... .

    for example if we want to see all the convert all the contents of a binary file(executable, shared libraries, object files) we say:

    hexdump binaryfilename
    

    e.g.

    hexdump /bin/bash
    

    but readelf is the best utility for analyzing elf(executable and linking format) files. so if we say:

    readelf -a /bin/bash
    

    all the contents in the binary file bash would be shown to us, also we could provide different flags for readelf to see all the sections and headers of an elf file separately, for example if we want to see only the elf header we say:

    readelf -h /bin/bash
    

    for reading all the segments of the file:

    readelf -l /bin/bash
    

    for reading all the sections of the file:

    readelf -S /bin/sh
    

    but again as summary , for reading a normal file like "hello.c" and a binary file like bash in path /bin/bash in linux we say:

    xxd hello.c
    
    readelf -a /bin/bash
    
    0 讨论(0)
  • 2020-11-29 15:19

    As a fallback there's always od -xc filename

    0 讨论(0)
  • 2020-11-29 15:21

    See Improved Hex editing in the Vim Tips Wiki.

    0 讨论(0)
  • 2020-11-29 15:24

    Hexyl formats nicely: sudo apt install hexyl

    0 讨论(0)
提交回复
热议问题