brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: file reads the contents to tell you what files really are

Files
~/tips/tip-files-file-command-real-type

file photo.jpg data.bin

Identify a file by its contents, whatever its extension claims.

An extension is only part of a name. When something called photo.jpg won’t open, I ask file what is inside it.

file photo.jpg data.bin

It looks at the bytes and answers per file. A program renamed to look like a picture is reported as what it is, something like ELF 64-bit LSB pie executable, and a mystery data.bin may turn out to be plain ASCII text. You’ll also meet answers for archives, images with their dimensions, and scripts.

For scripts, the MIME type is easier to compare than the description:

file --mime-type -b photo.jpg

-b leaves out the file name, so you get just the type. Wildcards work too, which is a quick way to survey a folder of downloads without extensions:

file ~/Downloads/*

I find it especially handy before piping something unknown into a tool that expects text, or when a “zip” download turns out to be an HTML error page.

It’s an educated guess based on known patterns. A damaged file can keep a valid header and still be reported as fine, and unusual formats often come back as plain data. It tells you nothing about whether a file is safe to open. Some minimal systems and containers don’t include it.

Further reading: file(1) man page

More Files tips sha256sum -c --ignore-missing SHA256SUMS xxhsum -H64 backup.tar > backup.xxh unzip -j archive.zip -d out/ Files > More > Select > pick files > More > Compress ls -lhS /var/log All Files tips (15) All topics

Link