5 terminal commands every Linux newbie should know

5 terminal commands every Linux newbie should know
linux tux mascot logoImage: Larry Ewing, Simon Budig, and Garrett LeSage

I’m a big fan of the anime series Neon Genesis Evangelion. One of the quotes from it that stands out in my head is, “Man fears the darkness, and so he scrapes away at the edges of it with fire.” For newcomers to the world of Linux, the black screen of the terminal can seem like a deep, foreboding darkness, which is desperately replaced by a GUI whenever possible. It doesn’t have to be that way.

A graphical user interface makes modern computing more enjoyable and easier to use the majority of the time. After all, placing an Amazon order using a text-mode browser in a terminal sounds like an over-enthusiastic exercise in masochism. We like our GUIs and graphical browsers, but there are times when you’ll find yourself in the world of the command line. Like any new tool, knowing a few basics can keep your blood pressure in check when a GUI fails to start, or you need to perform maintenance.

For starters, here are five commands you should become comfortable with as a Linux user.

1. sudo

If there is one command that should be treated with equal parts certainty and respect, it’s sudo. Sudo’s effect is quite simple: It runs any command that follows it with superuser (or root) privileges. Running commands with sudo is necessary when doing things like updating the system or changing configuration files.

sudo in action

Since /mnt is owned by root, you have to use sudo to create a directory in /mnt.

Sudo also gives the user the power to destroy a system or violate the privacy of other users. This is why you’ll see the following lecture the first time you use sudo on a system:

We trust you have received the usual lecture from the local SystemAdministrator. It usually boils down to these three things:1)Respect the privacy of others.2)Think before you type.3)With great power comes great responsibility.

If you’re looking to edit or change any file that’s outside of your user’s home directory, there’s a good chance you’ll have to use sudo to do it. To be able to use sudo, your user needs to be in the sudoers file or part of a superuser group (usually “wheel” or “sudo”). Ubuntu offers a great guide on the sudoers file.

sudoers file

A look at a typical sudoers file, where the groups that allow root access are specified. It is very unwise to allow sudo access to a user or group without requiring a password.

Since sudo carries so much power, it goes without saying that you should not type it before a command if you don’t know what the command does. There’s an old prank online that instructs newbies to type sudo rm -R /. (Don’t do this.) The command recursively deletes every file on your system, and your OS will happily do it without further prompting. As the lecture file says, when using sudo, “think before you type.”

2. Your package manager tools (yum, apt, or pacman)

The number one reason you’ll be using sudo is to add or remove programs from your PC via your package manager. Although the three major package managers I mention here all differ in their respective command arguments and grammar, they are all capable of the same three basic functions: installing a package, removing a package, and upgrading all the packages on the system. (Note: Unless you’re logged in as root, you will need to prepend these commands with sudo.)

sudo pacman -Syu

A system upgrade using pacman on Arch Linux. Note the use of sudo before the pacman command.

yum (Red Hat/Fedora/CentOS)

Install a package:

yum install <package>

Remove a package:

yum remove <package>

Upgrade the system:

yum update

apt (Debian/Ubuntu/Mint)

Install a package:

apt install <package>

Remove a package:

apt remove <package>

Upgrade system:

apt updateapt upgrade

pacman (Arch/Manjaro)

Install a package:

pacman -S <package>

Remove a package:

pacman -R <package>

Upgrade the system:

pacman -Syu

All of these package managers have many more features than what I’ve listed here, but these three functions are what you’ll use most of the time. Whatever Linux distribution you choose, you should be comfortable with the package manager, and know where to find its documentation.

3. systemctl (Systemd)

For the longest time, background programs called daemons were started using a series of scripts called initscripts. For newcomers, initscripts were hard to read and interpret or change. More recently, initscripts have been replaced by a service management application called Systemd. If you’re running a recent Linux distribution, there’s a good chance that Systemd is starting the services you need.

systemctl enable NetworkManager

Disabling and re-enabling the NetworkManager service to run at boot time.

One of the chief complaints about Systemd is that it can do too much. (Unix programs usually aim to do one thing, and one thing very well.) However, there are five keywords you should consider with systemd.

To start a service, simply use the start keyword:

systemctl start <service name>

Similarly, you can restart a service if it has failed, or if its configuration has changed:

systemctl restart <service name>

To stop a service, use stop:

systemctl stop <service name>

To enable the service at boot, you can use the enable keyword:

systemctl enable <service name>

And finally, you can disable a service to keep it from starting at boot:

systemctl disable <service name>

4. ls

The ls command is simple and straightforward, but it is more useful than one might think. The ls command lists the files and folders in a given path. By default, it lists the files and folders in the current working directory (usually the user’s home). You can find the contents of a given path too.

ls example

There are several options to ls, but the most common to use is -l, which shows file permissions and ownership.

So what makes this Linuxy-version of the Windows dir so useful? Well, for one you can look in subdirectories for configuration files. It’s also helpful for looking for file names in an environment without a GUI. Since Linux filenames and commands are case-sensitive, it’s handy to know exactly how something is spelled. In short, think of ls as your scout that you can use to peek around the system.

5. man

Sometimes you need help. Sometimes you need help and you don’t have access to the internet. Those are dark times. In those situations, man can save your butt.

The command man is short for manual, and provides “online” (stored on your computer) access to command documentation. If you need reminding about what chmod does, you can simply type in man chmod into your terminal to read about the command. You can scroll up and down in the man page by using the arrow keys or PgUp and PgDn keys. When you’re done reading, hit Q to quit.

man ls

The manual page for ls.

Though man can be useful when an internet connection isn’t available, Google is a much better resources when you actually are online. It’s worth noting that the first few Google results you’ll get for a given command like chmod will be a web version of the man page.

Wrapping up

There are many, many more commands to learn, but dipping your toes into the world of text-mode commands can help you understand your system better and make it a bit less scary. While there are lots of ways to accomplish things in a graphical desktop, console commands are still the fastest way to update your system.

Console commands also have the added benefit of showing errors when things go wrong. That means when an update fails, you can generally tell if something was wrong with the package, or if you simply didn’t have an internet connection.

With a bit of practice, anyone can start banging out terminal commands with confidence and the skillful use of sudo.

For more information on Linux commands, there is a great cheat sheet atPixelbeat.org.

admin

Leave a Reply

Your email address will not be published. Required fields are marked *