←
Command Line
/
Guided Lab Identify Files with file
60:00
Click the virtual machine below to start practicing
>_ Tekhnikum | Lab
- Setting up virtual machine…
- Preparing lab files…
- Starting terminal services…
This lab machine has stopped
Your progress through the guide is saved. Start a fresh machine to keep practicing.
Introduction
Linux doesn't trust file extensions. file looks inside a file and reports what it actually is. Some of the files in ~/project have misleading names.
This lab is the hands-on companion to the file lesson from Linux Journey (CC BY-SA 4.0).
Extensions Can Lie
file photo.jpg
photo.jpg: ASCII text
Despite the .jpg, it's plain text.
Check Everything at Once
* matches every name in the directory:
file *
One of these files is really a PNG image. Rename it to real-image.png:
mv <the-image-file> real-image.png
MIME Types and Brief Output
-i prints the MIME type that browsers and mail use; -b (brief) leaves out the filename:
file -i index.html
file -b tool.txt
tool.txt turns out to be a program.
Summary
file name reports what a file contains, not what its name suggests.
file * checks every file in a directory.
-i prints the MIME type; -b omits the filename.