Most recent converts to Linux spend most of their time in the GUI —
the graphical desktop (whether Gnome, or KDE, or XFCE, or some other
interface) that’s made to look and act somewhat like Windows and Mac.
But if you spend all your time in the GUI, you’re missing out.
The Linux command-line gives you a lot of power — it lets you do
tasks that are difficult or impossible with the GUI, and for tasks that you do a lot, such as launching the same applications everyday, it’s often faster. When you read about using the command line, which is often abbreviated to CLI for “command-line interface”, they usually mean typing commands into a terminal. This is a term leftover from the olden days of interfacing with mainframes via dumb terminals which had no processing power of their own; they were pretty much just monitors and keyboards. When we refer to a Linux terminal it’s a software application, and if you want to get technical it’s a terminal emulator.
So the first step is finding a terminal on your Linux system, and I haven’t seen a Linux distribution yet that didn’t include several by default. On KDE look in your start menus for Konsole, and on Gnome look for Terminal or Gnome-Terminal. There are dozens of different terminals: xterm, aterm, rxvt, eterm, and many more. Apparently Linux geeks love terminals.
Wading through all those menus to launch our terminal is tedious, so our first step in learning mighty command-line powers is a fast keyboard shortcut for opening a “run command” dialog. This way we can quickly type in the name of an application to start it. Press the Alt and F2 keys at the same time, and on KDE you see something like Figure 1. Gnome calls it “run application” and it looks similar, with one very nice addition– an alphabetical graphical menu to browse. On KDE type in konsole and press Run, and in Gnome type terminal or gnome-terminal and press Run. Lo and behold, your shiny terminal opens before you, just like Figure 2 shows.
What you see displayed in the terminal is the command prompt, in this example carla@xena:~$. This tells you the name of the user, the name of their computer, ~ means the current directory is Carla’s home directory, and $ means ordinary, unprivileged user. When you see # that means all-powerful root user.
Now that you have a terminal open you can start entering commands. First, let’s take a look at a really useful Linux command-line utility
called locate. It’s a very fast way of finding files on your system.
For instance, suppose somebody sent me a funny picture a
while back of a squirrel with tiger stripes.
I know I saved it, but I can’t remember where!
But it probably had “squirrel” or “tiger” or maybe both
somewhere in the name.
From the desktop I can do simple filename searches, but it’s a bit
slow and, as you’ll see, it’s not as flexible. So let’s try it from
the command line. Type:
$ locate tiger
Don’t type the $, that’s just to show you that this command can be run as an ordinary user. locate tiger
gets quite a few matches (Figure 3). The
list is short enough that I could read through them all, but why not
get the computer to do that work for me?
So what if I try:
$ locate squirrel
instead?
Eek! I’m not going to tell you how many files that found. Suffice to
say that I take way too many pictures of squirrels, and finding one
specific file in that mess looks way too hard.
The locate command depends on a database of every filename on your system, and most Linux distributions automatically update this database daily. It doesn’t hurt to update it manually just to make sure, using the updatedb command. You need root powers to do this, which on Ubuntu you get with the sudo command:
$ sudo updatedb
It can take a few minutes, so be patient.
Fortunately, the Linux command line offers a way to combine these two
searches. It’s called a pipeline, because it uses the ASCII
vertical bar character sometimes called a “pipe”, which is the uppercase of the back-slash key:
|
.
Most basic Linux commands are set up so that you can “pipe” the output
of one program into the input of another. The simplest version of a
pipeline is one that uses the program “less” to display a file in
screen-sized chunks. less shows you one page at a time; hitting
the spacebar will take you to the next page, while q will quit.
Try it for yourself in your terminal window. In case you don’t have as
many squirrel pictures as I do, try searching for files containing “cat”:
$ locate cat | less
I bet you didn’t know you had so many cat files on your system!
Remember, q will get you out of less and back to the command prompt.
Okay, how do we use a pipeline to help find the tiger-squirrel
picture? With the grep command, probably the single most
useful command Linux offers.
“grep” is kind of a nasty name — there’s some disagreement on what it
stands for, including “Globally search for Regular Expressions and Print”
and “General Regular Expression Parser”.
But it’s an incredibly useful program that prints just the
lines matching a particular pattern.
For instance, to combine the squirrel search and the tiger search,
you just pipe one search through grep, passing grep the second
pattern:
$ locate squirrel | grep tiger /home/akkana/Images/MiscImages/tiger-squirrel.jpg
locate squirrel
found all those squirrel images, then
grep searched through all of them to find any that also had “tiger” in
the name. Now I know exactly where the file is.
Pipelines aren’t limited to just two commands, though. For instance,
remember that long list of files with cat in the name? I know there’s
a program called “cat”; suppose I want to know how many of those other
files with “cat” in the name are programs.
Programs are usually located in /usr/bin, but sometimes they’re in
/bin or some other place. But they usually have “bin” in the name
somewhere. So if I take all the files that have both “cat” and “bin”
in the name:
$ locate cat | grep bin
I can then find out how many lines there were, by using the useful
wc (word count) program:
$ locate cat | grep bin | wc -l
wc -l
says to count the number of lines (that’s ell for
“lines”, not a one) — if you omit the -l part, it prints lines,
words and characters.
On my system I have 34 programs with cat in the name.
How many do you have?
Akkana Peck is a freelance
programmer whose credits include a tour as a Mozilla developer.
She’s also the author of Beginning
GIMP: From Novice to Professional.
This article was first published on LinuxPlanet.com.
Please enter your content here.Ethics and Artificial Intelligence: Driving Greater Equality
FEATURE | By James Maguire,
December 16, 2020
AI vs. Machine Learning vs. Deep Learning
FEATURE | By Cynthia Harvey,
December 11, 2020
Huawei’s AI Update: Things Are Moving Faster Than We Think
FEATURE | By Rob Enderle,
December 04, 2020
Keeping Machine Learning Algorithms Honest in the ‘Ethics-First’ Era
ARTIFICIAL INTELLIGENCE | By Guest Author,
November 18, 2020
Key Trends in Chatbots and RPA
FEATURE | By Guest Author,
November 10, 2020
FEATURE | By Samuel Greengard,
November 05, 2020
ARTIFICIAL INTELLIGENCE | By Guest Author,
November 02, 2020
How Intel’s Work With Autonomous Cars Could Redefine General Purpose AI
ARTIFICIAL INTELLIGENCE | By Rob Enderle,
October 29, 2020
Dell Technologies World: Weaving Together Human And Machine Interaction For AI And Robotics
ARTIFICIAL INTELLIGENCE | By Rob Enderle,
October 23, 2020
The Super Moderator, or How IBM Project Debater Could Save Social Media
FEATURE | By Rob Enderle,
October 16, 2020
FEATURE | By Cynthia Harvey,
October 07, 2020
ARTIFICIAL INTELLIGENCE | By Guest Author,
October 05, 2020
CIOs Discuss the Promise of AI and Data Science
FEATURE | By Guest Author,
September 25, 2020
Microsoft Is Building An AI Product That Could Predict The Future
FEATURE | By Rob Enderle,
September 25, 2020
Top 10 Machine Learning Companies 2021
FEATURE | By Cynthia Harvey,
September 22, 2020
NVIDIA and ARM: Massively Changing The AI Landscape
ARTIFICIAL INTELLIGENCE | By Rob Enderle,
September 18, 2020
Continuous Intelligence: Expert Discussion [Video and Podcast]
ARTIFICIAL INTELLIGENCE | By James Maguire,
September 14, 2020
Artificial Intelligence: Governance and Ethics [Video]
ARTIFICIAL INTELLIGENCE | By James Maguire,
September 13, 2020
IBM Watson At The US Open: Showcasing The Power Of A Mature Enterprise-Class AI
FEATURE | By Rob Enderle,
September 11, 2020
Artificial Intelligence: Perception vs. Reality
FEATURE | By James Maguire,
September 09, 2020
Datamation is the leading industry resource for B2B data professionals and technology buyers. Datamation's focus is on providing insight into the latest trends and innovation in AI, data security, big data, and more, along with in-depth product recommendations and comparisons. More than 1.7M users gain insight and guidance from Datamation every year.
Advertise with TechnologyAdvice on Datamation and our other data and technology-focused platforms.
Advertise with Us
Property of TechnologyAdvice.
© 2025 TechnologyAdvice. All Rights Reserved
Advertiser Disclosure: Some of the products that appear on this
site are from companies from which TechnologyAdvice receives
compensation. This compensation may impact how and where products
appear on this site including, for example, the order in which
they appear. TechnologyAdvice does not include all companies
or all types of products available in the marketplace.