The Linux Command Line: What It Is And How to Use It

Use the Linux command line like a pro

The Linux command line is a text-based system that passes commands to the computer and returns results to the user. In the late 1990s, it was next to impossible to use Linux without relying on the command line. Since then, things have changed considerably—now, you can use the Linux desktop without ever having to type a single command.

Although that evolution is helpful in bringing new users into the open source fold, it avoids one inescapable truth: The command line offers a significant amount of power and flexibility to the operating system. This is true for Linux, Windows, and macOS. And even though some commands are incredibly complex, most are not.

Let’s find out what the Linux command line is and how you can make use of it.

What Is the CLI?

A screenshot of a Linux terminal.

CLI stands for command-line interface. It’s the tool you use to run commands. It's comprised of two distinct components:

  • Shell: The shell is an interpreter that can transform what you type into something usable by the operating system. Linux supports several different shells, the most common being bash (which stands for Bourne Again Shell). Without the shell, what you type at the command prompt would not be usable by the operating system.
  • Terminal emulator: This small window emulates a Linux terminal. Most often Linux servers do not include a desktop, so when you log into such a machine, you are greeted with a terminal that includes a shell prompt and not much more. On a system with a desktop, that terminal has to be emulated. Apps like GNOME Terminal, Konsole, and LXTerminal offer this functionality.

Why Use the CLI?

If you’re using Linux on the desktop, the chances of you needing to use the CLI are not nearly as great as they’d be if you were working on a server. If you’re working on a Linux server, you generally only use a shell prompt to interact with the operating system.

However, making use of the CLI is an efficient means of handling many tasks. On top of it making your life more efficient, it also brings a level of flexibility to the desktop you won’t find in the GUI tools. Although you’ll find a GUI tool for every task you run on Linux, some of those graphical interfaces don’t cover the entirety of what the CLI option offers. For example: Most Linux desktops use pulseaudio for sound.

Screenshot of the sound Settings in Elementary OS.

One thing you cannot do, however, is restart the pulseaudio daemon from the GUI. In some instances (such as when using the Audacity sound recording tool), pulseaudio must be restarted. Instead of rebooting the computer, you could open a terminal emulator and issue the command:

pulseaudio -k

That’s not something you can do from the desktop settings tool.

How to Run Commands

Most commands in Linux are global, which means you can run any command you want (so long as you have permission to do so) from anywhere you want. So if you need to list the contents of a directory, open a terminal emulator and issue the command:

ls
Because the command is global (installed system wide), you don’t have to issue the full path for the command:

Screenshot of the ls command.

Most every command can be run with options, which is what makes the CLI so powerful. The standard format of a command run with options is the command string followed by its options. Sticking with our ls example, let’s say you want to want to view more information about the files and folders within a location. For that you could add the -l option (which is for long list). This new command would be

ls -l
The -l option instructs ls to also list information like permissions, owner, group, size, creation date, and name. You could also add hidden files (files that begin with a .) with the -a option with the command

Screenshot of the ls -la command.

To make that last command more efficient, you can combine options together, as in


Command Permissions

Some commands can only be successfully run by users with super-user permissions. For example, rebooting a computer requires elevatedpermissions. You can't open a terminal emulator and issue the command

reboot
without being informed you don’t ha
Screenshot of a failed reboot command.

In order to run a command that requires admin permissions, you’ll have to employ a tool such as sudo. To successfully reboot a Linux computer from the CLI, that command would be

sudo reboot
Sudo allows normal user accounts to run commands with super-user privileges. Always use sudo with caution. For instance, if you were to issue the command:
sudo rm -rf / 
you would delete everything on your system. Not only would that render your system completely unusable (requiring you reinstall the operating system), but you’d a

That’s how powerful the CLI can be (and why you should run commands with sudo using a good deal of caution).

Commands Every Beginner Might Want to Know

There are plenty of commands every beginning Linux user should know. These commands aren’t challenging and can make your daily life a bit more efficient.

To create a new directory, use the mkdir command. For example, to create a new directory named data in your home directory, open a terminal emulator and issue the command

mkdir /home/USER/data
(where USER is your username). You could make that command easier to type by using the home directory shortcut, ~/ (Which takes the place of /home/USER/). So the new command would be

Screenshot of the mkdir command.

To move into that newly created directory, issue the command cd data. This command assumes you are already in your home directory. If you are in any other directory on your system, make use of the /home/USER/ shortcut:


Screenshot of the cd command.

If you’re not sure which directory you are in, issue the

pwd
command (which stands for “print working directory”) to print the name of the directory you are cu
Screenshot of the pwd command.

To rename a file or directory, use the move command, which is mv. To rename the newly created data directory to docs, issue the command:

mv ~/data ~/docs
In similar fashion, use the mv c
Screenshot of the mv command.

To delete the ~/docs folder, use the rm command. However, you couldn’t just run the command

rm ~/docs
because ~/docs is a directory and we have to instruct the rm command it will be deleting more than just a file. Use the r option (for “recursive”):

Screenshot of the rm command.