How to Check a File Type in Linux

Use file to identify text, archives, executables and other file formats from the command line.

A filename extension is only a hint. Linux can inspect the bytes inside a file, and `file` is the standard quick way to ask what kind of data you actually have.

Step by step

1 Identify one file

$ file archive.tar.gz

Reports the detected file format and often additional details such as compression.

2 Check several files

$ file *

Runs the same identification against each matching directory entry.

3 Check an executable

$ file /usr/bin/bash

Useful for distinguishing architectures and executable formats.

4 Combine with extraction tools

$ file download && tar -tf download

Identify an archive before choosing the command that should process it.

Tips worth knowing

Frequently asked questions

How do I know what type a file is in Linux?

Run `file filename`.

Can file detect archives without extensions?

Usually yes; it can inspect known file signatures without relying on the filename extension.

Is file the same as MIME type?

Not exactly. `file --mime-type` can report a MIME type, while the normal output often gives a more descriptive classification.

The commands behind it

tar

Create and extract archives: tar.gz, tar.bz2 — with the flag combinations finally explained.

sha256sum & md5sum

Fingerprint files, verify downloads, and prove two files are identical.

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.