Walker News

Using Linux od Command To View File In Bit

Jerry Peek wrote about Comparing Binary Data in Linux / Unix with few useful file utilities. (You can read the article in Google cache version without need to login – Refer to “How to read Experts Exchange premium contents with Googlebot membership“)

It prompts me to realize how useful the od command is to fix some Linux problems, e.g. compare files in binary form or bit level (i.e. 0 and 1), fix Bad Interpreter error message when executing Linux Bash shell scripts, etc.
As shown in the diagram, a Bash shell script called simple.sh that was scp from Windows Vista to Red Hat Linux failed to execute properly, with an error message “bad interpreter no such file or directory”.

How to use Linux od command to view a file in binary or bit level, i.e. 0 and 1.

I know this error is caused by the difference of file encoding between Linux and Windows Vista and it can fixed by simply executing dos2unix command, i.e.

dos2unix simple.sh

Though, the od command is nice to tell the differences of file encoding – before and after executing dos2unix conversion utility.

For example, the –c option of octal dump utility attempts to display all printable ASCII characters, otherwise octal dump is substituted.

od -c -w10 simple.sh

The first column of od output represent the offset of file (the number of bytes from the beginning of the file) and by default it’s shown as octal format! However, the –Ad option will display file offset in decimal format that is readable by most non-technical people.

od -Ad –w10 -to1 simple.sh

The –w10 limits each line of octal dump to display 10 character bytes (with –to1 option). The last line indicates how many bytes the od command has displayed, i.e. 24 or 030 (octal code) in the screenshot above is equal to 24 bytes (i.e. 24 characters)!

Custom Search

  1. apsara 11-11-09@14:56

    hi… its basic but do try and kill this worm… what is the diffrence between the od(octal dump) command and the same with a (-b) option i.e. (od -b) command… both returns different octal values… please help…

2014  •  Privacy Policy