Build a Better Process

Linux file Command Summary with Examples

Linux file allows you to display a file's type.
  1. Purpose - Learn what file is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with file.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial Linux file, 17 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / file-command.html

An ad-free and cookie-free website.

Examples of the Linux file Command


Learn to find a file's type at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux file Command Summary with Examples (3:54)

Video Script

The Command and Why You Need It

Our seventeenth word, or command to memorize is file from the category Files.

file allows you to display a file's type.

Common Linux file Options
-options description
--help Print help screen
-f, --file Input a list of files

Recall from our video (tutorial) #11 we saw how the type command showed a command's type? Now we're interested in displaying a file's type, meaning is it text, or a binary like an excutable, or an image file.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The file command has 25 options and the argument is the file, or list of files to test.

As with many commands, a double-dash --help option is available.

The details here get complicated, so at this point, I'll just mention that the -f option allows you to input multiple filenames at once.

So why is file an important command? Well, file helps you get organized, and could help prevent you from running executables you know nothing about. And now you know how to do that.


Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go, let's start by locating the file command, with whereis file.

$ whereis file file: /usr/bin/file /usr/share/file /usr/share/man/man1/file.1.gz

There it is in /usr/bin. So let's use file on file by typing file /usr/bin/file.

$ file /usr/bin/file /usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked inperpreter /lib6 4/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=51a63fc391865d8e708e15d4321c6c1a stripped

Replay that if it helps. Ok, we see it's an executable, and other technical details we shouldn't be concerned with right now.

Next, let's compare that output to the file from the previous video16.txt, using file video16.txt.

$ ls -aog total 32 drwxr-xr-x 2 4096 Oct 11 10:35 . drwxr-xr-x 5 4096 Sep 27 22:24 .. -rw------- 1 30 Sep 27 22:31 .bash_history -rw-r--r-- 1 220 Sep 27 22:24 .bash_logout -rw-r--r-- 1 3515 Sep 27 22:24 .bashrc -rw-r--r-- 1 675 Sep 27 22:24 .profile -rw-r--r-- 1 100 Oct 8 17:58 video11.txt -rw-r--r-- 1 0 Oct 9 10:36 video16.txt -rw-r--r-- 1 176 Oct 5 13:48 video5.txt $ file video16.txt video16.txt: empty

Empty. And then video11.txt?

$ file video11.txt video11.txt: ASCII text

That's an ASCII text file, very good.

And last, let's look at a configuration file like .bashrc as well.

$ file .bashrc .bashrc: ASCII text

Text as well. Excellent.

A Final Tip

Okay now you know how to use file. And you know the syntax for commands, options and arguments.

One last tip about the file command. The user manual here, (man file) while advanced, does make for interesting reading. With coffee of course.

Okay, thanks for visiting today. I hope this was a fun introduction to the file command.

Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:

What's Next?

The only way we can compete with the big corporations and offer better tutorials is with your support. Subscribe at YouTube, follow @factorpad and join our no-spam email list.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / file-command.html

linux file command
file command
linux ascii file
linux file type
linux file command syntax
linux file summary
linux file command examples
linux file options
linux file tutorial
linux file format
find linux executable
find linux file type

A newly-updated free resource. Connect and refer a friend today.