/ factorpad.com / tech / linux-essentials / file-command.html
An ad-free and cookie-free website.
Beginner
Learn to find a file's type at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux file Command Summary with Examples (3:54)
Our seventeenth word, or command to memorize is file
from the category Files.
file
allows you to display a file's
type.
-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
.
There it is in /usr/bin
. So let's
use
file
on
file
by typing
file /usr/bin/file
.
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
.
Empty. And then video11.txt?
That's an ASCII text file, very good.
And last, let's look at a configuration file like
.bashrc
as well.
Text as well. Excellent.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
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.
touch
command,
hit Back.which
command,
click Next./ factorpad.com / tech / linux-essentials / file-command.html
A newly-updated free resource. Connect and refer a friend today.