file command in Linux with examples Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 5 Likes Like Report The 'file' command in Linux is a vital utility for determining the type of a file. It identifies file types by examining their content rather than their file extensions, making it an indispensable tool for users who work with various file formats. The file type can be displayed in a human-readable format (e.g., ASCII text) or as a MIME type (e.g., 'text/plain; charset=us-ascii'). The file command tests each argument provided to categorize it accurately.How the 'file' Command WorksIt has three sets of tests as follows:filesystem test: This test is based on the result which returns from a 'stat' system call. The program verifies that if the file is empty, or if it's some sort of special file. This test causes the file type to be printed.magic test: These tests are used to check for files with data in particular fixed formats.language test: This test search for particular strings which can appear anywhere in the first few blocks of a file.Syntaxfile [option] [filename]Example of 'file' Command You can use the 'file' command with various files to determine their types:file email.py # Displays type of 'email.py'file name.jpeg # Displays type of 'name.jpeg'file Invoice.pdf # Displays type of 'Invoice.pdf'file exam.ods # Displays type of 'exam.ods'file videosong.mp4 # Displays type of 'videosong.mp4'Commonly Used Options with 'file' Command'-b', '--brief': This is used to display just file type in brief mode. Syntax:Syntax: 'file -b filename'Example:file -b email.py # Shows just the file typefile -b input.txt # Shows just the file typefile -b os.pdf # Shows just the file typeHere, we can see that file type without filename.'*' option : Command displays the all files's file type. Syntax: file *The output shows all files in the home directory'directoryname/*' option : This is used to display all files filetypes in particular directory. Syntax:Syntax: 'file directoryname/*'Example:file work/*The output shows all files in a particular directory.'[range]*' option: To display the file type of files in specific range. Syntax:Syntax: file [range]*Example:file [a-z]*file [a-e]* The output shows the range of files.'-c' option: Cause a checking printout of the parsed form of the magic file. This option is usually used in conjunction with the '-m' flag to debug a new magic file before installing it. Syntax: 'file -c'Example:file -c'-f' option: Read the names of the files to be examined from namefile (one per line) before the argument list. Either namefile or atleast one filename argument must be present; to test the standard input, use ‘-’ as a filename argument. Syntax:Syntax: 'file -f -''-F' option : File and file type are separated by :. But we can change separator using -F option Syntax:Syntax: 'file -F "-" filename'Example:file -F - input.txtfile -F + os.pdf The output shows file and file types are separated by - and +.'-i' option: To view mime type of file. Syntax:Syntax: 'file -i filename'Example:file -i input.txtfile -i os.pdf'-N' option: Don't pad filenames so that they align in the output. Syntax: 'file -N *'Example:file -N *'-s' option: For special files Syntax:Syntax: 'file -s filename'Example:file /dev/sda file -s /dev/sda file /dev/sda5 file -s /dev/sda5 filenames: Displays file types of multiple files Syntax:Syntax: 'file filenames'Example:file input.txt .local Desktop'-z' option: Try to look inside compressed files. Example:Syntax: 'file -z flash.tar.gz''--help' option: Print a help message and exit. Create Quiz Comment D dileep1998 Follow 5 Improve D dileep1998 Follow 5 Improve Article Tags : Linux-Unix Explore Getting Started with LinuxIntroduction to Linux Operating System7 min readLINUX Full Form - Lovable Intellect Not Using XP2 min readDifference between Linux and Windows7 min readLinux Distributions6 min readDifference between Unix and Linux6 min readInstallation with LinuxInstallation of Arch Linux in VirtualBox4 min readFedora Linux Operating System5 min readHow to install Ubuntu on VirtualBox?6 min readHow to Install Linux Mint?3 min readInstallation of Kali Linux in Virtual Machine2 min readHow to Install Linux on Windows PowerShell Subsystem?2 min readHow to Find openSUSE Linux Version?2 min readInstallation of CentOS2 min readLinux CommandsLinux Commands15+ min readEssential Unix Commands7 min readFind Command in Linux with Examples7 min readLinux File SystemLinux File System12 min readLinux File Hierarchy Structure5 min readLinux Directory Structure6 min readLinux KernelLinux Kernel4 min readKernel in Operating System3 min readHow Linux Kernel Boots?11 min readDifference between Operating System and Kernel3 min readLinux Kernel Module Programming: Hello World Program7 min readLinux Loadable Kernel Module7 min readLoadable Kernel Module - Linux Device Driver Development4 min readLinux Networking ToolsNetwork configuration and troubleshooting commands in Linux5 min readHow to configure network interfaces in CentOS?5 min readCommand-Line Tools and Utilities For Network Management in Linux8 min readLinux - Network Monitoring Tools4 min readLinux ProcessProcesses in Linux/Unix5 min readHow to Manage Process in Linux4 min readGetting System and Process Information Using C Programming and Shell in Linux2 min readProcess states and Transitions in a UNIX Process4 min readLinux FirewallLINUX Firewall7 min readiptables command in Linux with Examples7 min readHow to Configure your Linux Firewall - 3 Methods12 min readShell Scripting & Bash ScriptingIntroduction to Linux Shell and Shell Scripting7 min readUnderstanding Terminal, Console, Shell and Kernel3 min readHow to Create a Shell Script in linux7 min readShell Scripting - Different types of Variables4 min readBash Scripting - Introduction to Bash and Bash Scripting12 min readBash Script - Define Bash Variables and its types12 min readShell Scripting - Shell Variables6 min readBash Script - Difference between Bash Script and Shell Script4 min readShell Scripting - Difference between Korn Shell and Bash shell3 min readShell Scripting - Interactive and Non-Interactive Shell3 min readShell Script to Show the Difference Between echo â$SHELLâ and echo â$SHELLâ4 min readLinux Administrator SystemWhat is Linux System Administration?6 min readBeginner's Guide to Linux System Administration5 min readHow to Monitor System Usage, Outages and Troubleshoot Linux Servers6 min readLinux - Systemd and its Components3 min readBoot Process with Systemd in Linux3 min readHow to Control Systemd Services on Remote Linux Server2 min readHow to Start, Stop and Restart Services in Linux Using systemctl Command9 min read Like