Which UNIX command is used to display a file's contents in octal (and other base) representations?
-
Acd
-
Bod
-
Cof
-
Doct
-
ENone of the above
Answer
Correct Answer: od
Explanation
Introduction / Context:Inspecting raw file data is a common need when debugging encodings, binary formats, or control characters. UNIX provides tools to dump file contents in octal, hexadecimal, and ASCII, enabling byte-level verification independent of text encodings or editors.
Given Data / Assumptions:
- We need a standard utility to output bytes numerically.
- Compatibility with POSIX environments is implied.
- Command should support octal natively.
Concept / Approach:
od stands for “octal dump.” It can print data in octal by default and also in hex or character formats using options (e.g., -t x1 for hex bytes, -c for characters). The other choices are not standard UNIX utilities for octal dumps: cd changes directories; of and oct are not standard commands.
Step-by-Step Solution:
Select the utility explicitly designed for octal dumps: od.Use options as needed (e.g., od -An -t o1 file) for pure octal bytes.Verify output corresponds to byte values.Apply to binary or text files as required.Verification / Alternative check:
Running od -c /bin/sh | head demonstrates character and octal output, confirming the command's purpose.
Why Other Options Are Wrong:
- cd: directory navigation only.
- of, oct: nonstandard/incorrect command names.
- None of the above: incorrect because od is correct.
Common Pitfalls:
- Misreading base; use -t to specify exact type and width.
- Forgetting to suppress addresses with -An when parsing programmatically.
Final Answer:
od.