Difficulty: Easy
Correct Answer: file
Explanation:
Introduction / Context:
On Unix and Linux systems, knowing the actual type of a file is essential for troubleshooting, scripting, and security hardening. Filenames do not reliably indicate content; for example, a file named note.txt could be a binary. The command that inspects content and metadata to report a human-friendly type is purpose-built for this task.
Given Data / Assumptions:
Concept / Approach:
The file command uses a database of magic numbers and heuristic checks to identify file types by content, optionally following symlinks and examining encoding. It reports types such as ELF executable, JPEG image, ASCII text with UTF-8 encoding, gzip-compressed data, and more. This is fundamentally different from listing, paging, or concatenating files.
Step-by-Step Solution:
Verification / Alternative check:
Cross-check with tools specific to the suspected format (for example, strings, hexdump, identify for images). The file result should match the specialized tool's conclusion about format and encoding.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming an extension dictates type, running file on symlinks without -L if you need the target's type, or ignoring compressed/archived layers where file may report the container (for example, 'gzip compressed data').
Final Answer:
file
Discussion & Comments