file
file linux command cheatsheet by Thamizhiniyan C S
Introduction
The man command is used to determine the file type.
Syntax
file [-bcdEhiklLNnprsSvzZ0] [--apple] [--exclude-quiet] [--extension] [--mime-encoding] [--mime-type] [-e testname] [-F separator] [-f namefile] [-m magicfiles] [-P name=value] file ...
file -C [-m magicfiles]
file [--help]
Important Flags
Flag | Description |
---|---|
| Changes the command output to the one used by older versions of MacOS. |
| Changes command output to brief mode. |
| Creates an output file that contains a pre-parsed version of the magic file or directory. |
| Checks the printout for the parsed version of the magic file. |
| Prints internal debugging information in the standard error format. |
| On filesystem error, issues an error message and exits. |
| Excludes a test from the list of tests performed on a file. |
| Excludes tests that the file command doesn't know about. |
| Prints a list of valid extensions for the file type. |
| Uses the provided string as a separator between the file name and file type. |
| Uses a provided text file as a list of files to test. The list must contain only one file name per line. |
| Disables following symbolic links. |
| Changes the command output to a MIME-type string. |
| Changes the command output to a MIME-type string and only displays the specified element (type or encoding). |
| Keeps the test going after the first results match. |
| Shows a list of matching patterns in descending order of strength. |
| Enables following symbolic links. |
| Uses an alternative magic file provided by the user. |
| Doesn't pad the file names to align with the output. |
| Flushes the output after checking each file. |
| Attempts to preserve the last time the file was accessed to make it look like the file command didn't test it. |
| Sets various parameters, such as max bytes or recursion, count, and length limit. |
| Disables translating unprintable characters. |
| Enables reading special files. |
| Disables sandboxing on systems that support it. |
| Displays the version of the file command. |
| Checks compressed files. |
| Checks compressed files and only displays file type without the compression. |
| Displays a null character after the end of the file name. |
| Displays the help message. |
Examples
Command | Description |
---|---|
To find the correct type of a file named 'filename'. | |
Test multiple files simultaneously. | |
View the file type in brief mode for a file named 'text.zip'. | |
Display brief version of file type output. | |
List each file type in the current directory. | |
List each file type inside a specific directory. | |
View the MIME file type of a file named 'filename'. | |
Check detailed information and content of a compressed file like ZIP or gzip. | |
Test a compressed file to detect its content. | |
Display only the file type of a compressed file like ZIP or gzip. | |
View the parsed version of a file, useful for debugging magic files. | |
Display the check printout for the parsed version of a file. | |
List all file types within specified Regex-style ranges. | |
Test files in a directory within the range of names from 'a' to 'l'. | |
List all file types within specified Regex-style ranges. | |
Test files listed in a text file (one file per line). | |
Test a special system file. | |
Fully test a special system file (requires root). | |
Define '+' as a separator between file name and type in output. | |
Remove padding between file name and type in output. |
Last updated