Linux is an extremely flexible operating system, and you can configure it any way you’d like. That means that if you come from Windows, you can make Linux act a lot like Windows. If you come from macOS, you can make Linux act like that too. The fact that Linux can do that is awesome, and it shows off its versatility. But we can also learn it as Linux itself.

If you want to be fast and productive, you’ll need to ditch a lot of the things you take for granted, including clickable buttons, graphical windows, and mouse support. There’s a significant learning curve here that you’ll have to overcome, and for a while, you’ll probably even be slower than you were when you started. But if you stick with it, and you learn Linux the hard way, the time that you save in the long run will be more than worth it. If you learn how to harness the real power of Linux, your life as a computer user will become infinitely simpler.

Before we start, let me level your expectations. This is a getting started guide, and won’t even come close to learning Linux as a whole. It’s designed to ease you into using the terminal in Linux, and to give you the ability to the most common tasks in it. With that said, let’s get started!

What Is a Linux “Distro”?

You may hear this term a lot when talking about Linux: “distro” (short for distribution). You may also hear the word “flavor”. They mean the same thing, but I’ll use “distro” for the sake of consistency.

First of all, let’s get a common misconception out of the way: Linux is not a full operating system in the way that macOS or Windows is. Instead, it is something called a “kernel”. In computing, a kernel is essentially the core of an operating system. Windows has its own kernel, and macOS has its own. The kernel is most of the operating system and handles the important stuff, but it’s not everything. In short, the kernel is software that acts as the connection between the computer’s hardware and the rest of its software, while an operating system is software that acts as a connection between the user and hardware. If you want a deep dive into what a kernel is exactly, check out wikipedia. Since it’s not an entire operating system, it can’t run on its own and must be combined with some other tools to turn it into one. Linux is also open source, meaning that the code for it is available to the public.

With the combination of Linux being a kernel and open source, many people modify it and make their own “versions” of Linux. We call these versions “distros”, and there are a ton of them (and I mean a ton!). Just like Linux, most of these distros are also open source, and also like Linux, they are modified to make different versions of them. So in that way, it’s like people are making distros of distros! We call a collection of distros that are all based on the same distro a “family” of distros. Here’s a graph of some of the most popular distros:

Quick note: there are nodes above Linux, but considering that this is a Linux guide, we’ll pretend they don’t exist for now.

Any distros that contain children are considered to be a family. You can see that the most popular ones according to that graph are Debian and RedHat. Ubuntu is also considered to be a family of distros even though it’s a child of Debian. There is a lone distro in that graph that’s highlighted: Alpine. Alpine is not as popular as Debian or RedHat distributions, but it’s incredibly useful. Alpine is very minimal, only containing what it needs to be able to run. As a result, while RedHat and Debian distros are gigabytes in size, Alpine is only about 100 megabytes large. This is largely because Alpine contains no graphics, only text. Alpine provides no mouse support by default; there are no images or windows. This makes it the perfect distribution for this guide, and will enable us to learn Linux at its core. To install Alpine, follow this guide.

The Terminal: An Introduction

If you followed the Alpine installation guide successfully, after you log in to your system, you should see something like this:

This beauty is your terminal. This is your alternative to clickable buttons and graphical windows. Here, instead of interacting with everything with your mouse, you will only use your keyboard. While it may not look like much, the terminal is /extremely/ powerful. Almost everything you can do in a graphical setting like Windows or macOS, you can do in the terminal, only you can do it faster and you have more tools available to you. Learning how to use the terminal is at the core of being a productive computer user, this is what is going to save you time and energy in the long run.

Here’s where the learning curve begins, so buckle up, because we’re going straight for it.

Commands

How do we interact with a computer in the usual setting? Typically, there’s some button or icon that you click on, and something happens based on that interaction. But if there are no buttons in the terminal, how are we supposed to interact with anything? In the terminal, instead of buttons, we have commands.

A command is a program that, after invoking it, produces some behavior. That’s all it is: just a program, not much different than what you are used to working with. The only difference is that a command usually doesn’t have a graphical interface associated with it. When we installed Alpine, a number of commands were installed with it. One such command is ”echo”. The echo command prints out whatever you put after it. Let’s try it! Type in echo “Hello, world!”, then press enter.

Nice! We got some output from the command. Double quotes are special in the terminal, and that’s why they weren’t outputted as well.

Believe it or not, this is all that using the terminal is: enter a command, get a response, repeat. Using the terminal isn’t hard, and that’s not what people struggle with. What people struggle with is what commands to use, and when to use them. There are a ton of commands, and its a lot to remember. Some commands have tons of uses that you would never think of. Take the one we just used, for example: echo. On the surface, echo may seem useless. Why would anybody just want to output what they just typed? In practice, and when combined with other commands, it is a very powerful tool that I use on a day-to-day basis.

Don’t try to memorize every command available to you in Linux. When you start, only learn the commands that you need to know to do what you want. If you try to learn everything, you’ll get nothing done, and you’ll never stop. Instead, look out for Linux articles that catch your eye. I’ve learned more than I’ve expected in articles titled “10 Linux Commands That Will Save You Time”. They’re useful!

On a similar note, don’t try to memorize any commands at all. Instead, just get stuff done. If you need to look up how to do the same thing over and over, so be it! That’s how you learn how to use the terminal. In a way, you want your fingers to remember the commands for you instead of your brain. You want to be able to think of what you want to get done, and you want your fingers to start typing to get it done, and that is only achieved by doing things over and over. So keep at it, stubbornly try to do everything in the terminal, and you’ll be able to do a lot in the terminal before you know it.

Next, you’ll learn how to do the most common thing that people do with a computer: create, delete, and manipulate files and directories.

Files and Directories

Note: Linux doesn’t have folders; Linux has directories. They can be thought of as the same thing, but are different. Folders are more of a Windows construct. Functionally, they are used for the same purpose, however.

To start, let’s learn how to do something very important: make files and directories, and manipulate them. There are quite a few commands to learn for this purpose, but it’s the core of using a computer. If you learn no other commands, you should learn these.

In the next couple subsections, we’ll learn how to do everything that you would be able to do in Windows’ file explorer, or macOS’s Finder. But before we start learning commands, let’s talk about Linux’s file structure.

In Linux, every directory and every file is stored within on big directory, called root (not to be confused with the root user). The root directory is represented by a forward slash: /. The location of every directory or file we want to refer to in Linux is represented as a path from the root directory to the file. Take the following graph of a Linux file system, for example:

Quick note: directories are usually represented with a trailing slash. Therefore, any node in the graph above that has a trailing slash is a directory.

If we wanted to represent the location of file1.txt, the path would be /home/user1/file1.txt. We separate each file or directory with a forward slash in Linux as opposed to the (in my opinion, ridiculous) backslash that Windows uses by default, starting with the initial / to represent that we’re starting at the root directory. It’s very similar to a web URL.

Alright, now we can get into some commands!

pwd

First off, we want to learn how to tell where we are in the file system. In Linux, we have something called the “working directory”. This is the directory that we are currently in. For each terminal session, we can only have one working directory at a time. To see what our working directory is, we can use the pwd command, which stands for “print working directory”.

Every Linux user has a “home” directory that the user can put all their files in, and that’s the directory we start in by default after logging in (therefore, our initial working directory). For the root user, the path to that directory is /root, and is the path that pwd output. Keep in mind that /root should not be confused with the root directory. Instead, /root is a directory called root under the root directory (/).

Cool! But how can we see the things that are in the working directory?

ls

The ls command will output a list of the directories or files in a directory. Give it as shot. You should get no output:

There’s no output because there aren’t any /non-hidden/ files or directories in the current working directory. In Linux, a file or directory is considered to be hidden if it begins with a period. There’s nothing different between a hidden file or directory and a non-hidden one, other than it takes more work to see hidden ones. You usually hide files or directories that are for configuration, but you can hide any file or directory. To have ls display hidden files and directories as well, we run ls -a. The “-a” that we add is called a flag. We’ll get into what those are later, but you can think of them as modifiers to a command, and they change the behavior of it.

After adding the -a flag, we get some output. There are three entries: ., .., and .ash_history. What these entries are actually for isn’t important yet, but we’ll get into it later. What’s more important is the color of the entries. The colors tell you what kind of entry it is. Here’s a table of some of the colors and what they represent:

Color Entry Type
Blue Directory
White Regular File
Green Executable File

There are more colors, but these are the three most common ones that you’ll see.

touch, mv, cat, echo, and cp

So far we’ve learned how to see what directory we’re currently in, and we’ve learned how to see what is inside a directory. Now it’s time to make our own files! That’s where touch comes in.

The touch command simply creates an empty file. To use it, run touch X, where X is the name of the file to create. Try creating an empty file called “test.txt”. After you do, use the ls or ls -a command to see if it’s in the current directory.

Awesome! But there’s a problem. I changed my mind, and I now want the file to be called “example.txt”. But how do we rename files? That’s what the mv (short for “move”) command is for. In Linux, you don’t really rename things. Instead, you move them to new locations, which, in practice, produces the same effect as renaming them. To use mv, run mv SRC DEST, where SRC is the file you want to rename and DEST is the new name for it. Let’s rename test.txt to example.txt:

The mv command can also be used for moving a file or directory into another directory, and we’ll learn how to do that in the next section.

The purpose of a file is to contain data, and there are a lot of times we want to see the data in a file. For that, we have the cat command (which stands for “concatenate”). To use cat, run cat X, where X is the file to get the data of. Let’s get the contents of example.txt:

After we run it, we don’t see any output. That’s because touch creates an empty file, and we haven’t put anything in it quite yet. Let’s fix that!

Remember the echo command from earlier? We can use that to put data in a file. To do that, run echo "TEXT" > X, where TEXT is the data to put in a file, and X is the file to put it into. Put the phrase “Hello, world!” in example.txt, then use cat to see the contents of it:

Now we get output! Let’s clarify what we did with that last line. We can split the line into two parts: echo "Hello, world!", and > example.txt. The first part we’re familiar with. It takes in the text between the quotes and outputs it. The second part is not a part of echo, however. This is a more advanced terminal construct called a redirection. A redirection takes the output of a command and puts it somewhere else. In this case, we’re taking the output of echo, and putting it in example.txt. There are other places that we could redirect to, but we won’t worry about that for now. We’ll gradually cover redirections as we learn new Linux features. Keep in mind that there are /much/ better ways to edit the contents of a file, and we’ll learn those later, but for now, let’s ignore them.

We can also use redirections to copy a file. The basic concept is this: use the cat command to get the contents of a file, then redirect the contents to a new file named example-copy.txt. Let’s try it:

Quick note: If the file doesn’t already exist, it will be created for you. If the file does exist, it will be overwritten.

That’s a fun use of redirects and all, but there’s a better way to copy a file: the cp command (short for “copy”). The usage for the cp command is identical to the mv command. Run cp SRC DEST, where SRC is the file to copy, and DEST is the file to copy it to. Let’s create a third copy of example.txt named example-copy-copy.txt for fun:

mkdir and cd

Now let’s learn how to make our own directories and how to navigate to other directories. To make a directory, we use the mkdir command. To use it, run mkdir X, where X is the name of the directory to make. Let’s create a directory called temp:

If you use the ls command again, you should see a blue entry named temp. Now let’s move example.txt into that directory. Before we used the mv command to rename a file, now let’s use it for the purpose it’s named after. If we provide a directory as our destination to mv, the file will be placed in it. Let’s move it:

It looks like example.txt is gone from our working directory and is now in temp. But what if we need to access that file again? We have to enter that directory, and for that, we have the cd command (short for “change directory”). To use cd, run cd PATH, where PATH is either a relative or absolute path to the directory you want to go into.

Detour: Before we use cd, let’s take a detour about relative and absolute paths because it’s very important to understand them. So far, we’ve been using relative paths. As the name implies, a relative path is relative to another directory, specifically the working directory. In practice, if you use a relative path, it will be added on the end of what pwd would output. Up until now, we have been in the /root directory, and every time we’ve referenced a file, it has been relative to that /root directory. In practice, this means that when we refer to example.txt, Linux knows we /actually/ mean /root/example.txt. As for absolute paths, they’re just the full path to a file or directory, starting at root. The path I mentioned a moment ago - /root/example.txt - is absolute because it starts at the root directory. In reality, every path is an absolute path, but in a lot of cases, Linux will handle making relative paths absolute for you.

Let’s use cd to enter the temp directory that we just created:

If you run ls, you’ll notice that the file we moved in here earlier is output, and if you run pwd, you’ll notice that our working directory has changed. Great! But what if we want to go back to the directory we came from? Now it’s time to learn what “.”, “..”, and “~” mean.

Each symbol is shorthand for an absolute path. The . symbol represents your current working directory. If you run cd ., you’ll notice that you’re still in the directory you started in. It’s not very useful on its own, but when combined with other concepts, it’s very useful. The .. symbol represents the parent directory ()the directory that contains the current directory). For example, if our working directory is /root/temp, .. would represent /root. Finally, the ~ symbol represents the current user’s home directory. When we learn about environment variables, I’ll show you how to figure out what that is, but just know for now that the root user’s home directory is /root.

With that said, we can get back to where we started in two ways! We can either go to the parent directory with .., or we can go to the home directory with ~, which currently represent the same thing. Use either one to go back:

rm

All we have to learn now is how to delete files, and to do that, we use the rm command (short for “remove”). To use rm, run rm X where X is the file you’d like to remove. We have too many copies of example.txt, so let’s remove example-copy-copy.txt:

Let’s also remove the temp directory that we created earlier. We can’t just delete a directory, however. Since directories are large and contain many things, rm doesn’t allow you to delete them by default. Instead, we have to use a flag: -r. The -r flag stands for recursive and deletes both a directory and everything in it. Try it by running rm -r temp:

Awesome! Now the only file left is example-copy.txt. It’s very important to keep in mind that using rm deletes a file permanently. There’s no recycle bin that the file gets into it that you can easily recover. So be very careful!

Bonus: The clear Command

In the images above, the terminal’s been pretty messy. I’ve had old commands showing, and I’d like to clean it up and start with an empty screen. The clear command will fix that for us:

Next Steps

In the next part, we’ll learn how to create a user, install new tools, and handle environment variables. If you’re ready to move on, click here.