Don't just stare at your Linux terminal

Nishant SharmaNishant Sharma
4 min read

As a developer shifting to Linux as my primary operating system has been one of my the best decision. It not only gives you complete control of your system but also let's you learn a lot about how operating systems work underneath. Of course you will break your system, a lot of things may not work if you are going with distributions like Arch and will be frustrated for a few months but trust me it's worth it.

Assuming you have installed your Linux flavor and have been staring at the terminal for a while. I will start with some basics.

When you first start the terminal it should look similar to this

01:25:01 nishant@localhost ~ →

The 1st part is time. The 2nd is your username, the part after @ is your hostname. We will talk about them later. The last is a sign ~ called a tilde. Let's do a small exercise here. Execute the following command:

ls

1st rule of fight club. I want you to run this command after every command in this article.

This command will list all the directories and files in your current directory. Now a directory is just another name of folder You should see Desktop, Downloads, Pictures, Music or anything else.

I want you to go inside a directory . Execute the following command:

cd <folder_name >

cd stand for change directory it will take you inside the pointed directory.

Now create a new directory here. Execute the following command:

mkdir <name_your_folder>

Go into the created directory. Execute the following command:

touch trump.sh

This will create a new file in the current directory.

Execute the following command:

cd ~

I hope you are not forgetting rule 1. You are back to the beginning.

So a tilde (~) references to the current user, it will always take you back to user's home directory no matter where you are. You may be wondering what does he means by user's home directory.

Execute the following command:

cd /

Now you should see a bunch of new directories. Some of them are bin boot dev etc home lib lib64 root ... Go into the home directory. When viewing the contents of this directory you will find your username there. The home directory contains the directory of each user so when you create a new user in Linux and log in as that user you will be inside one of the these directory as per your username.

The / is the root directory. This is the starting point of everything all the directories are inside the / or root directory. Now you may be wondering why do I see another root directory when doing ls. This because the root directory inside / is the home directory of the root user. Like jason inside home is the home directory of the jason user. Below is the image for reference.

enter image description here

The root user has the power to do basically anything. It can block a users access to certain directory even delete the whole Linux system. To login as root user execute this command:

su -

Enter the password and now you are a super user.

We will continue the search in another article. We will explore what are the directories inside / are meant for in a new article.

Let’s try to do another exercise. Change yourself back to normal user from root user

su <your_username>

I want you to go the directory where the trump.sh file was created by now you should be able to so that.

.sh files are shell scripts that can be coded to execute a certain program. To run a script execute

./<your_script_name_trump.sh_in_this_case>

This will throw an error saying permission denied. You need to make this script executable. You can modify permission of a script using the command

chmod 755 <your_script_name_trump.sh_in_this_case>

The script should have changed it’s color to green. The chmod command is used to change the permission of a file. I will explain this in detail in anytime soon.

For now this script is executable you can run the above command to execute a script.

It will not output anything we need to write bash code here so for that run

vim <your_script_name_trump.sh_in_this_case>

This will open an editor. Vim is the default editor for Linux. You won’t be able to copy paste anything here. Press i here to start writing, it stand for insert else you won’t be able to write anything in vim. Write the below code.

!#/bin/bash

echo "Hello World"

Now to exit vim press “esc” → press “:” → press “wq”. You will see :wq being written in the bottom left.

Now execute the script it should print Hello World.

Congrats you have learned about basic Linux commands, directories and scripts. This is just the beginning but essentials. We will meet in the next article.

0
Subscribe to my newsletter

Read articles from Nishant Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nishant Sharma
Nishant Sharma

I am web developer. A competitive Coder. Always Learning.