# man > file(1)

---
type: CommandReference
command: file
mode: man
section: 1
source: man-pages
---

## Quick Reference

- `file {{path/to/file}}` — Determine file type of the specified file.
- `file -b {{path/to/file}}` — Do not print the filepath (brief mode).
- `file -z {{path/to/file.zip}}` — Look inside a compressed file.
- `file -s {{path/to/file}}` — Allow `file` to work with special or device files.
- `file -k {{path/to/file}}` — Don't stop at the first match; keep going.
- `file -i {{path/to/file}}` — Determine the MIME type string.
- `file -m {{magicfile}} {{path/to/file}}` — Use an alternate magic file.
- `file -C -m {{magicdir}}` — Compile a magic file for faster loading.

## Name

`file` — determine file type

## Synopsis

shell
file [options] file ...
file -C [options] [-m magicfiles]
file --help
## Options

### General Options

- `-b, --brief` — Do not prepend filenames to output.
- `-C, --compile` — Write a pre-parsed `magic.mgc` file from a magic file or directory.
- `-c, --checking-printout` — Print parsed form of the magic file (for debugging with `-m`).
- `-e, --exclude testname` — Exclude a test type: `apptype`, `ascii`, `encoding`, `tokens`, `cdf`, `compress`, `csv`, `elf`, `json`, `soft`, `tar`, `text`.
- `-f, --files-from namefile` — Read file names from `namefile` (one per line).
- `-h, --no-dereference` — Do not follow symlinks (default unless POSIXLY_CORRECT is set).
- `-L, --dereference` — Follow symlinks (default if POSIXLY_CORRECT is set).
- `-m, --magic-file magiclist` — Use specified magic file(s) or directories (colon-separated).
- `-s, --special-files` — Read block or character special files (e.g., raw disk partitions).
- `-z, --uncompress` — Look inside compressed files.
- `-Z, --uncompress-noreport` — Look inside compressed files, but report only the contents.
- `--exclude-quiet` — Like `--exclude` but ignore unknown test names.
- `--help` — Print help message and exit.

### Output Formatting

- `-F, --separator string` — Use `string` as separator between filename and result (default `:`).
- `-i, --mime` — Output MIME type strings (e.g., `text/plain; charset=us-ascii`).
- `--mime-type` — Print only the MIME type.
- `--mime-encoding` — Print only the MIME encoding.
- `-N, --no-pad` — Do not pad filenames for alignment.
- `-n, --no-buffer` — Flush stdout after each file (useful for pipes).
- `-r, --raw` — Do not translate unprintable characters to octal.
- `-0, --print0` — Output a null character after the filename. Repeat for NUL-delimited output.
- `--extension` — Print a slash-separated list of valid extensions.
- `--apple` — Output old MacOS file type and creator code.

### Magic File Handling

- `-k, --keep-going` — Don't stop at the first match; continue and prepend `\012- ` to subsequent matches.
- `-l, --list` — Show list of magic patterns and their strengths.
- `-p, --preserve-date` — Preserve access time of files (via `utime`/`utimes`).
- `-P, --parameter name=value` — Set limits: `bytes` (1048576), `elf_notes` (256), `elf_phnum` (2048), `elf_shnum` (32768), `encoding` (65536), `indir` (50), `name` (50), `regex` (8192).
- `-S, --no-sandbox` — Disable sandboxing (needed for external decompressors with `-z`; ineffective on Debian).
- `-v, --version` — Print version and exit.

## Examples

shell
$ file file.c file /dev/{wd0a,hda}
file.c:   C program text
file:     ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
          dynamically linked (uses shared libs), stripped
/dev/wd0a: block special (0/0)
/dev/hda: block special (3/0)
shell
$ file -s /dev/wd0{b,d}
/dev/wd0b: data
/dev/wd0d: x86 boot sector
shell
$ file -i file.c file /dev/{wd0a,hda}
file.c:      text/x-c
file:        application/x-executable
/dev/hda:    application/x-not-regular-file
/dev/wd0a:   application/x-not-regular-file
## See Also

- [hexdump(1)](https://www.chedong.com/phpMan.php/man/hexdump/1/markdown)
- [od(1)](https://www.chedong.com/phpMan.php/man/od/1/markdown)
- [strings(1)](https://www.chedong.com/phpMan.php/man/strings/1/markdown)
- [magic(5)](https://www.chedong.com/phpMan.php/man/magic/5/markdown)

## Exit Codes

- `0` — Successful operation.
- `>0` — Error encountered. With `-E`, errors cause exit code >0; otherwise diagnostic messages are printed but exit code remains 0. Errors include: file not found, no read permission, or file type cannot be determined.