The extension of upload.bin cannot be trusted.
Inspect its content and print only a MIME type such as text/plain or image/png.
Which command is correct?
file primarily detects a type from content. -b omits the filename and --mime-type requests only the MIME type.
Detailed explanation
ls -l upload.binIncorrect. ls only displays metadata and does not determine the content type.
Incorrect. ls only displays metadata and does not determine the content type.
file upload.binIncorrect. file examines content but also prints a descriptive filename and type.
Incorrect. file examines content but also prints a descriptive filename and type.
file -b --mime-type upload.binCorrect. It detects the content and prints only the MIME type.
Correct. It detects the content and prints only the MIME type.
cat upload.binIncorrect. cat displays bytes and does not classify the content.
Incorrect. cat displays bytes and does not classify the content.
Try it yourself
An example you can run in a temporary verification environment.
printf 'plain text
' | file -b --mime-type -Expected result
text/plainKey points
- file inspects content
- --mime-type prints a MIME type
- -b omits the filename
Notes
- Environment: file 5.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.