LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What information does the file command provide?

file tells you a file's true type by peeking at its actual contents — its "magic number" — not by trusting the extension.

This matters because Linux doesn't care about extensions. Unlike Windows, where .exe decides whether something runs, Linux determines a file's nature from what's inside it. A program named report with no extension runs fine; a file named photo.txt might really be a PNG. file reads the first bytes (the "magic number" that formats stamp at their start) and reports what it genuinely is:

$ file /etc/passwd
/etc/passwd: ASCII text
$ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64
$ file image.png
image.png: PNG image data, 1920 x 1080, 8-bit/color RGB

The security angle is real: an attacker can name a malicious script invoice.pdf to look harmless, but file invoice.pdf will expose it as a shell script regardless of the name. So file is both a practical "what is this?" tool and a small safety check.

Tip: run file unknownthing before you cat it. If file says "ELF executable" or "data," it's binary — catting it will spray garbage (and possibly control codes that scramble your terminal). file first, cat second.

  • Determine if file is binary or text before viewing

Common file types:

Output Meaning
ASCII text Plain text file
ELF executable Linux binary program
Bourne-Again shell script Bash script
symbolic link Symlink (shows target)
directory It's a directory
empty Zero-byte file

Tip: Always file before cat on unknown files - don't cat binary files to your terminal!

From Quiz: LIOS / Files and Directories | Updated: Jul 14, 2026