How to Find Out File Types in Linux

In Linux operating systems, everything is treated as a file. Understanding file types is crucial for system administration and file management. In UNIX systems, there are seven standard file types

  • Regular files Contains data, text, or program instructions

  • Directory files Contains lists of other files and directories

  • Symbolic link files Points to another file or directory

  • Character special files Represents devices that transfer data character by character

  • Block special files Represents devices that transfer data in blocks

  • Socket files Used for inter-process communication

  • FIFO (Named Pipe) files Used for communication between processes

While file extensions like .txt, .py, or .go can indicate file types, Linux doesn't rely solely on extensions. The file command is a powerful utility that examines file contents and determines the actual file type regardless of extension.

The File Command

The file command performs tests on files and prints their type based on content analysis, not just extensions. It examines the file's magic number, header information, and content patterns.

Basic Usage and Version Information

To check the version of the file utility

file -v

This produces output similar to

file-5.44
magic file from /etc/magic:/usr/share/misc/magic

Identifying File Types

To determine a file's type, simply pass the filename as an argument

file mybashfile.sh
mybashfile.sh: Bourne-Again shell script, ASCII text executable

The command can identify various file types including executables, images, compressed files, and text files.

Advanced File Command Options

Examining Multiple Files

To examine files listed in a text file (one filename per line)

file -f filelist.txt

Special Device Files

For block or character special files, use the -s option

file -s /dev/sda1
/dev/sda1: Linux filesystem data, UUID=a1b2c3d4-e5f6-7890

Compressed File Analysis

To look inside compressed files and identify their contents

file -z sample.tar.gz

For content information only (not compression details)

file -Z sample.tar.gz

MIME Type Output

To get MIME type strings instead of human-readable descriptions

file -i mybashfile.sh
mybashfile.sh: text/x-shellscript; charset=us-ascii

File Extensions

To see valid extensions for a file type

file --extension sample.png
sample.png: png

Performance Optimization

Skip specific tests to improve performance using the -e option

file -e ascii -e elf sample.bin

This skips ASCII and ELF tests, making the command execute faster when you know certain tests are unnecessary.

Common File Type Examples

File Type Example Output Description
Text File ASCII text Plain text document
Executable ELF 64-bit LSB executable Binary executable program
Image JPEG image data Picture file
Archive gzip compressed data Compressed archive
Directory directory Folder containing other files

Conclusion

The file command is an essential Linux utility for identifying file types based on content analysis rather than just file extensions. Its various options provide flexibility for different use cases, from basic file identification to performance-optimized testing and MIME type detection.

Updated on: 2026-03-17T09:01:38+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements