Determine whether extensionless downloaded_item is text, an image, or an executable by inspecting its contents.
Which command is appropriate?
file uses content signatures and related information rather than relying only on the filename extension.
Detailed explanation
file downloaded_itemCorrect. file downloaded_item reports a type based on content and signatures.
ls downloaded_itemIncorrect. ls lists a file and its metadata but does not identify content type in this way.
touch downloaded_itemIncorrect. touch creates or updates a timestamp.
type downloaded_itemIncorrect. type explains shell command resolution.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); printf 'hello\n' >"$tmp"; file "$tmp"; rm -f "$tmp"Expected result
末尾にASCII textなど、テキストと分かる種別が表示されるKey points
- file inspects content
- ls lists names and attributes
- type resolves commands
Notes
- Environment: Linux / fileコマンド / 一時ファイル
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
The file command can identify an object from its contents even when its name has no useful extension.
Check the side effect
Use a disposable file when testing identification commands and avoid treating a filename extension as proof.