1

I have a file called input_file, the following is the contents of input_file:

$ cat input_file     
1
2
3
4
5
6
7
8
9

then I run the following command:

$ od -to2 input_file

Output:

0000000 005061 005062 005063 005064 005065 005066 005067 005070
0000020 005071
0000022

My question is: What does the '005' mean in the output of od?

Ren
  • 273

2 Answers2

5

The output option you chose will take 2 bytes and display the result as an octal number.

So your starts with the digit 1 and the character \n. We can see this easier with od -cx:

% od -cx f
0000000   1  \n   2  \n   3  \n   4  \n   5  \n   6  \n   7  \n   8  \n
           0a31    0a32    0a33    0a34    0a35    0a36    0a37    0a38
0000020   9  \n
           0a39
0000022

With your od -to2 it will take those 2 characters and treat them as a 'low byte, high byte' of a 16bit number.

So the number works out to 10*256+49 (the \n is ASCII 10, and is the high byte; the 1 is ASCII 49 and is the low byte). That sum is 2609.

2609, in octal, is 005061 - which is the first number in your output. (In hex it's a31, which also matches the od -cx output).

So this is what you're seeing; od is converting your input into 16 bit integers and displaying them in octal.

1

It does not mean a lot. You can get a better picture using the -h (hexadecimal) option. For what it's worth, here's the first line rendered in decimal/octal/hexadecimal/character/utf8:

005061: 2609 05061 0xa31 text "\0121" utf8 \340\250\261
005062: 2610 05062 0xa32 text "\0122" utf8 \340\250\262
005063: 2611 05063 0xa33 text "\0123" utf8 \340\250\263
005064: 2612 05064 0xa34 text "\0124" utf8 \340\250\264
005065: 2613 05065 0xa35 text "\0125" utf8 \340\250\265
005066: 2614 05066 0xa36 text "\0126" utf8 \340\250\266
005067: 2615 05067 0xa37 text "\0127" utf8 \340\250\267
005070: 2616 05070 0xa38 text "\0128" utf8 \340\250\270

That is, every other byte is 012 (^J) and every other byte is a decimal digit. The utf8 came along for "free" because of the program I used (see hex).

Thomas Dickey
  • 76,765