Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm unreasonably excited about discovering xxd.


That's how I inspect a file in Vim: :%!xxd

It's even listed as a 'Convert to HEX' item in the Vim GUI menu.


xxd is on OSX, but not on FreeBSD. Under FreeBSD, I always use 'hd somefile.bin'.


I have xxd on my FreeBSD setup.

    uname -rms
    FreeBSD 9.1-RELEASE-p19 amd64
Although the xxd man page doesn't have the BSD label, and is from 1996, so I'm not sure if xxd only recently found its way into FBSD.

    This manual page documents xxd version 1.7

    AUTHOR
       (c) 1990-1997 by Juergen Weigert


It maybe in ports, but it's not part of the base install:

    $ xxd
    xxd: Command not found.
    $ uname -rms
    FreeBSD 9.1-RELEASE amd64
edit: fixed typo where I put xdd instead of xxd


I didn't add xxd on my local FBSD (installed last night) setup, and my remote FBSD shell has xxd installed by default...

    $ uname -rms
    FreeBSD 9.1-RELEASE-p7 amd64

    $ xxd -v
    xxd V1.10 27oct98 by Juergen Weigert
Perhaps different builds have different things included?


No, it installs as part of vim: https://news.ycombinator.com/item?id=6361210


http://vim.wikia.com/wiki/Improved_hex_editing

You're right, xxd is included with vim, but as an external program.

Vim provides this capability through the external program xxd, which is included by default in standard distributions of Vim.

My pedantic nature was hung up on the release dates of the respective programs, as xxd predates vim on Unix.


s/xdd/xxd/g


Sorry, that was a typo when posting on here. I did originally run it as xxd:

    root@primus:/usr/ports # xxd
    xxd: Command not found.
edit:

It doesn't show up in my ports either:

    root@primus:/usr/ports # make search name=xxd
    Port:   textproc/xxdiff
    Moved:
    Date:   2013-07-26
    Reason: Has expired: Depends on Qt 3.x

    Port:   textproc/xxdiff-scripts
    Moved:
    Date:   2013-07-26
    Reason: Has expired: Depends on Qt 3.x
Obviously xxdiff is a different (if you pardon the pun) utility, but xxd should show up in that list also.

edit 2:

Another comment on here might explain why you're seeing xxd and I'm not: https://news.ycombinator.com/item?id=6360814 (it's not a separate utility, it's part of vim)

Since I didn't install vim on that box (just use basic vi), xxd wouldn't have installed as part of it. Where as in a jail on the same box, xxd does exist:

    root@primus:/usr/ports # which vim xxd
    vim: Command not found.
    xxd: Command not found.
    
    root@primus:/usr/ports # jexec 1 which vim xxd
    /usr/local/bin/vim
    /usr/local/bin/xxd


    $ whereis xxd
    xxd: /usr/local/bin/xxd /usr/local/man/man1/xxd.1.gz
I don't see xxd anywhere in my ports tree.

Haha... What a trip. This is the sort of thing that I'll end up wasting half a day trying to get an answer to.


You wont see it in your ports tree because it's part of vim:

    $ grep xxd /usr/ports/editors/vim/pkg-plist
    bin/xxd


I've been told before that `od' is the most portable, although I prefer xxd in virtually all situations.


I've known about 'od', but I've always used 'hexdump' instead. Amusingly, I just noticed that they are literally the same (hard-linked) binary on OS X 10.6, even though the arguments differ somewhat. The man pages states that 'od' is part of POSIX, which aligns with your comment about portability.


This is also a common UNIXism: programs that behave differently depending on what they're called as. Another example is gzip (gunzip = gzip -d, gzcat = gzip -dc).


I never heard of it, untill today.

I can't remember how many times I implemented hexadecimal dumps and undumps because I didn't want to coerce od into working the way I wanted.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: