Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm reading Unix programming enviromnent. I came across the od command. It essentially works for the file contents but not for the directories.

When I do the following command :

od -c .

I get an error message like this :

od: .: read error: Is a directory
0000000

Why I get this error? I'm very new to the Ubuntu world.

Thanks in advance.

share|improve this question

3 Answers 3

  • If you want to do an octal dump of all files in and below the current directory, use find, e.g.:

    od -c `find -type f`

See man find or google for a tutorial on find for more information.

share|improve this answer

Why od -c directory Doesn't Work

A directory points to zero, one, or a bunch of files, it isn't really a file itself so it can't be processed by od or hd. Most Unix-like programs process files, not whole directories.

What to Do

You can list the contents of the directory with ls and then use the od -c or hd -b command to dump each file you want to examine. By doing them one-by-one you will know what each file contains.

(od -c file1 file2 stuffs file1 and file2 together and then dumps the whole thing. That makes it heard to find where the first one ends and the next one begins.)

You could also write a little script to give you, one by one, the filename of each of the files in a directory and then dump it in octal or hex. Here's an example:

 for f in *; do echo $f; od -c $f; done | less

for f in * assigns each file in the current directory to $f in turn; echo $f provides the name of the file on your terminal preceeding each file dump; od -c $f produces the dump; and done says to go on with the next file or finish if there aren't any more. |less says take all of the above and send the output through the "less" program which let's you look at it bit by bit rather than having everything roll off the top of the screen.

A script like this is interpreted by a program called by a "shell". When you are typing commands into the terminal you are talking to a "shell". By default, Ubuntu uses the "bash" shell.

If you would rather look at hex output you can use od -t x1 filename or hd filename. Use man od or man hd for more options.

share|improve this answer
od [options] [files] od --traditional [file] [[+] offset [[+] label] ]

Dump the specified files to standard output. The default is to dump in octal format, but other formats can be specified. With multiple files, concatenate them in the specified order. If no files are specified or file is -, read from standard input. With the second form, using the --traditional option, only one file can be specified.1

Read More

1Source:directory of Linux commands

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.