Start Your Terminal Journey Today!

Using and understanding your first commands

Start Your Terminal Journey Today!

This article assumes that you have a running Linux Operating System or a similar bash terminal.

In the realm of modern computing, where graphical user interfaces (GUIs) dominate, the Linux command line interface (CLI) stands as a timeless and powerful tool for users and developers. Understanding how the command line works can make your work more efficient and boost your productivity. However, for many beginners, the terminal might seem like a mysterious black box on the screen. It can be intimidating to face a text field without knowing what to do, unlike a GUI where you can explore by clicking around. But if you invest some time in learning it, the command line will become one of the most valuable tools in your arsenal, propelling you into a whole new level of expertise.

At first, the command line and input commands may seem unclear, but as we delve deeper, we realize it's just another way to interact with your computer. Think back to a time when computers were too slow for graphics and we didn't even have a mouse – yet, we still got our work done. This method of computer interaction continues today through the CLI. Sometimes, we don't need fancy graphics (or a mouse). However, using command-line tools isn't slow due to its history. In fact, it's the opposite – most command-line tools are small, incredibly fast, and can accomplish seemingly impossible tasks on a GUI. They say, "GUI makes easy things look easier, and CLI makes hard things possible." From navigating file systems to managing processes, manipulating data, and automating tasks, basic command-line tools prove to be a quicker option than GUI. In this article, we'll explore some essential command-line tools and how you can use them daily to speed up your workflow and boost productivity.

Remember, it’s just another way of interacting with your computer. Nothing to be scarred of. It’s only a matter of time until you master it!

Before we begin typing commands in the terminal, let’s get familiar with our terminal window. In many Linux distributions, you can open the terminal application by selecting it in the applications section or by using the shortcut Ctrl+Alt+T. Just to provide some context, I am using Ubuntu, a Debian-based Linux Operating System. The window that appears for you might look slightly different from mine, but there's nothing to worry about.

Let’s try to break down all the words and symbol that are presented on the screen!

1. pasha@pasha-pc : this part tells us my username (pasha) and the name of the system I am using (pasha-pc). This part will be different for you as you may have a different username and system name.

2. ~ : This squiggly symbol called Tilde tells us that we are currently operating from the home directory. Every user on the system has home directories where their personal files and media are stored.

3. $ : The dollar sign tells us that we are working as a ‘normal’ user. There is also a special user mode that has permissions to do things that a normal user cannot. It’s denoted by a # (hash) symbol and is called to be a ‘system administrator’ or a ‘root user’.

After learning what our terminal is trying to say, let's start off with our first command!

1. pwd : Print Working Directory

As the same suggests, pwd command is used to print the current working directory. It allows you to get the address of the directory you are currently in. Your Linux OS is made up of files and directories (aka ‘folders’ in windows). Whenever you start your Terminal, as a user, you are placed in one of the directories. And on using the pwd command you can see where you are in the file system.

The above image tells us that we are in /home/pasha directory.

Think of pwd as providing us with a GPS location within the maze of directories in your filesystem. To navigate effectively across directories, you must understand some key landmarks and how they are shown on the terminal. Let's begin by breaking down the above output.

/: represented by a forward slash (‘/’) is called the 'root directory' in your Linux filesystem. It sits at the top of the file address. Every files and directories are inside this directory.

Image taken from:homepages.uc.edu/~thomam/Intro_Unix_Text/Fi..

/home: This directory inside the root is where all the users are located. Think about how you choose a user to log in when you start your computer. If there are multiple users or accounts on this system, each will have their own starting home directory here.

/home/pasha or ~: I am logged into the system as the user 'pasha'. This is where my personal files are stored, known as the home directory. Each user has their own home directory.

2. ls : List

If pwd helps us know where we are in the file system, the ls command helps us to see the contents of the current directory we are in. Think of it as the flashlight in the dark world of the terminal that we use to figure out what's in the directory.

Notice that our output is on two different colors! The blue color means that they are a directory and the white ones are files. Colors may differ on your device.

Well, we can do a little more with the ls command. We will use something called an ‘option’ with ls command to improve our search results. ‘Options’ on command line are like ‘settings’ or ‘filters’ to help us do more with our commands. Usually, we use options with a ‘-’ hyphen. So, let’s try out some options on ls command.

Note: always remember to give a space between the command and it's option.

What a strange output! The -l option provides the 'long' output of the ls command, which is more detailed. Some parts may be unclear at the moment, but as we progress, you will understand it better. There are also some details that you don't need to worry about at this point.

drwxrwxr-x :

d : the first letter tells us the type of the file or directory. The letter ‘d’ represents a directory and a hyphen ‘-’ represents a file. And they are mostly in different colors.

rwx|rwx|r-x : the next three triplets of letter represents the permissions given to the file on user level, group level and to everyone else using the system. *

3 : it represents the number of hard links this file or directory may have. *

pasha : the first 'pasha' represents the owner of the directory.

pasha : the second 'pasha' represents the group associated with the directory or file.

4096 : the is the size of the directory in bytes. Which is 4 KB.

Mar 31 19:29 : this is the date and time the directory was last modified.

Desktop : this is the name of the directory.

Don’t fret much about the starred\ details as they are out of the scope of this article.*

Most commands come with an -h option that allows user to get a more ‘human readable’ output. Let’s try out the ls command with the combination of the -l option to see the difference!

While using the -h option, we can observe a slight change in the output. The file size is now shown as 4.0K instead of 4096. Combining multiple options can often lead to better results, as demonstrated above.

To enhance user-friendliness, Linux conceals certain directories and files in the background. These hidden files and directories begin with a period . in the file system. They might include configuration files and other items that are not typically needed for daily tasks. These hidden files are not displayed with a simple ls command. To locate such files, we utilize the -a option, which signifies 'all'.

The names starting with periods (.) represent hidden files and directories. If you check the upper left output, you'll see directories named with just a single period (.) and double period (..).

. : represents the current directory. We can use this to locate and change directories.

.. : represents the directory before the current one. We will understand this better in our next command when we learn how to change directories.

3. cd : Change Directory

As the names suggest, we use this command to change directories. Let's begin by checking our current location and the contents of this directory!

From using pwd we get to know that we are in my home directory and the output of the ls command let's know about the files and directories available to us.

Let's try to change to change our directory Desktop by using our cd command!

The output tells us that we have successfully changed to the Desktop directory. And a noticeable change in our terminal is the appearance of another word /Desktop before the $ symbol. In short, our terminal always tells us our current working directory.

cd commands accepts many different inputs to make our work easier. We previously talked about the single (.) and the double periods (..) that show up on ls -a command. Let’s see them in action!

we notice that there doesn’t seem to be any change. And that’s alright! Because a single period (.) denotes our current directory, so, using cd . brings us to our current directory and hence no change occurs.

Whereas using cd .. might yield a different result.

The double periods (..) denote the directory before the current one. Therefore, when we use cd .., we move back one directory. It's a simple way to go back one directory.

Let’s experiment with some other inputs with cd and decipher their results!

As mentioned earlier, the forward slash denotes the root directory (/) in the file system. Therefore, with the cd command, we can directly move to the root directory. Also, observe the change from the tilde (~) sign to the forward slash (/) just before the $ symbol as we switch directories.

Similarly, we can do this for our user home directory -

Again, observe the change of the (/) sign to the (~) tilde just before the $ as we change directories.

With so many ways to change directories, we can divide how we write an address to a file or directory in two ways

Absolute address: When we define a location to a file or directory using the full address, i.e., starting from the root directory or forward slash (/), that address is called an absolute address.

Relative address: When we define a location to file or directory using the relative address, i.e., relative to the current working we are in, that address is called a relative address.

The above command allows us to get back one directory using ../ and then we move to the Downloads/ directory. Here we change directories relative to the current directory unlike absolute address.

One more thing to always consider before writing an address is that the terminal handles spaces in file and directory names differently. If a directory has a space when using cd, make sure to put a backslash (\) before the space:

4. touch :

With this command, you can touch a file into existence. You can create a file simply by providing a filename.

If the file name that we want to create already exists, then this command updates its timestamp, the time of the last action taken on the file. For the above example, running the same command again after some time will update the timestamp of the file.

5. mkdir : make directory

This command, as the name suggests, allows us to create directories. We simply provide the desired name, and it creates the directory for us.

We can also create child directories, i.e., directories under directories, using the mkdir command with the -p (parent) option.

These are the 5 basic commands that you can use to navigate through the filesystem. They might appear simple initially, but they can be utilized in powerful ways!

Congratulations on making it this far! That must have been a lot of work. I suggest taking a break and celebrating if you can, letting that knowledge sink in. As you continue learning, you'll find that you don't need to memorize these commands; you'll naturally pick them up the more you use them! So, don't feel intimidated by them. Just use your terminal often, and you'll be good to go! ✨