file bepaalt het bestandstype op basis van inhoud — niet op bestandsextensie.
file bestand
file *
file document.pdf
# document.pdf: PDF document, version 1.7
file script.sh
# script.sh: Bourne-Again shell script, ASCII text executable
file afbeelding.png
# afbeelding.png: PNG image data, 1920 x 1080, 8-bit/color RGBA
file archief.tar.gz
# archief.tar.gz: gzip compressed data, from Unix
file /bin/ls
# /bin/ls: ELF 64-bit LSB pie executable, x86-64
| Optie | Betekenis |
|---|---|
-b | Zonder bestandsnaam (handig in scripts) |
-i | MIME-type tonen |
-z | Kijk ook in gecomprimeerde bestanden |
file -i foto.jpg
# foto.jpg: image/jpeg; charset=binary
TYPE=$(file -b --mime-type bestand)
if [ "$TYPE" = "application/pdf" ]; then
echo "PDF gevonden"
fi
Gebruik file als je twijfelt of een bestand is wat de extensie beweert — kwaadaardige bestanden hebben soms een misleidende naam.