Check sample.txt byte by byte to determine whether line endings are LF or CRLF.
Omit the offset column and display each byte in hexadecimal.
Which command is correct?
od dumps a file in a selected format. -An suppresses offsets and -t x1 selects one-byte hexadecimal output.
Detailed explanation
cat sample.txtIncorrect. cat displays text and does not reveal the byte values reliably.
Incorrect. cat displays text and does not reveal the byte values reliably.
wc -c sample.txtIncorrect. wc -c gives only a byte count.
Incorrect. wc -c gives only a byte count.
od -An -t c sample.txtIncorrect. -t c requests character notation rather than hexadecimal bytes.
Incorrect. -t c requests character notation rather than hexadecimal bytes.
od -An -t x1 sample.txtCorrect. It prints one-byte hexadecimal values without offsets.
Correct. It prints one-byte hexadecimal values without offsets.
Try it yourself
An example you can run in a temporary verification environment.
printf 'A
' | od -An -t x1Expected result
41 0d 0a(先頭の空白幅は環境により異なる)Key points
- CR is 0d and LF is 0a
- -An omits the address column
- x1 means one-byte hexadecimal
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.