file
Files and directories
Usage
file [path]Works out a file's type from its contents rather than its name; it ignores the extension, which is how a .jpg that is really a PDF is caught.
Common flags
| Flag | Meaning |
|---|---|
| -b | Print only the description, without the file name |
| --mime-type | Print the MIME type; the short form is -i on GNU, -I on macOS |
| -L | Follow symlinks |
| -z | Look inside compressed files |
| -s | Read block and character devices too |
| -i | On BSD and macOS this means do not classify contents, not MIME |
Examples
file screenshotSays PNG image data even with no extension.
file -b --mime-type report.pdfPrints application/pdf and nothing else.
file *Types every entry in this directory.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does file do?
Works out a file's type from its contents rather than its name; it ignores the extension, which is how a .jpg that is really a PDF is caught.
Q. How do I type it?
file [path] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man file. This command sits under Files and directories.
Related commands
man page: man file