Icons made: Dave Gandy, Source- https://www.flaticon.com/authors/dave-gandy"

Introduction to Linux: Part 1 — First Blood

Sarthak Pranesh
VIT Linux User Group

--

It’s almost been two years since I switched to Linux from a Windows environment where I used to game, make bad designs on Adobe XD ( not good at designing things ), and other stuff that a regular Windows user does. Initially it was quite frustrating and my system used to crash a lot mostly because I ran some command I didn’t have complete knowledge about and broke something. But soon I started to learn more and more about how the Linux system actually worked and the crashes started to reduce. Now I can proudly say it’s been 6 months without a crash :’)

I am making this tutorial series for beginners out there who have recently started to have a taste of Linux and want to know more terminal commands and how to use these commands to benefit them in their daily needs, and want to expand there knowledge about Linux further. So why wait, follow me along :)

What is Linux ?

Linux is the best-known and most-used open source operating system. As an operating system, Linux is software that sits underneath all of the other software on a computer, receiving requests from those programs and relaying these requests to the computer’s hardware.

-from opensource.com

Linux in the most simple term is a Unix-like operating system. Apart from being an operating system it is also a Kernel. A Kernel is something that handles all communication between the system hardware and the operating system, it has complete control on everything present in the system. The kernel is the core of an operating system and in most cases is the first program that gets loaded when the system initiates boot.

The kernel provides a secure environment as no application can directly access the hardware — all applications access the hardware through the kernel. This insures that any unwanted process/task is not carried out by any application. It is the duty of the kernel to provide all applications and the operating system with hardware resources, manage process, keep track of system tasks and daemons, etc.

So… is the shell or the terminal you see, the kernel ? NO, The Kernel is the core of the operating system which is managing the system you are currently running, where as The Shell is just an interface which allows you to communicate with the Kernel.

What are Distributions ?

A Linux distribution ( also called Flavors ) refers to an operating system that ships with a particular set of software collection, Linux kernel and a package manager. These particular set of software collection and other tweaks made to the operating system defines it’s use case greatly. For example — Kali Linux and Parrot OS are both Debian based operating systems well know for there Ethical hacking tools that come installed out of the box.

Here is a list of only some distributions ( No Priority )

  1. Linux Mint — A Ubuntu ( or Debian based ) based operating system that has a very familiar look and feel to it if you are switching to Linux, from Windows.
  2. Ubuntu — A Debian based operating system known for the flexibility and power it provides to it’s users. The most popular Linux operating system in the Linux community, especially in beginners.
  3. Cent OS — A popular and community supported alternative for the Red Hat Enterprise Linux.
  4. Manjaro — A Arch Linux based operating system. More popular in experienced Linux users, the project itself focuses on providing a more user friendly operating system.

The above Linux distributions are great for a start, but I have a personal favorite — Pop OS — a Ubuntu based operating system that provides more hardware support for laptops, better workflow management, easy installation of TensorFlow ( one line installation ), and a loads of other feature out of the box. It has been my daily driver for almost a year now.

Feel free to try out any of the above Linux operating system of your choice. A short note — if you are new to Linux or if this is your first time using a Linux based operating system I would recommend you to install Virtual Box and use Linux there for a while before installing it on your system and using it as your daily driver.

Lets get down to the basics !

There are broadly two ways to perform different tasks/operations on a Linux machine — using Graphical User Interface ( GUI ) or by using the shell. In this tutorial we’ll only cover performing tasks using the shell as GUI based method is quite straight forward to use.

Introduction to Terminal

The Terminal is just a session that often starts a shell in The Terminal Window. In Ubuntu or other Ubuntu based distribution the most common keyboard shortcut to open the Terminal windows is Ctrl+Alt+t . If that doesn’t open the Terminal window for you, then you can search on Google for your distribution specific keyboard shortcut. Other way to open Terminal is to open all applications menu and search for Terminal.

Your Terminal window might not look exactly the same but will have similar features.

The first thing you see is the username of the user ( in my case ‘sarthakpranesh’ ) followed by a separator @ after which we have the device name or the name of the computer system you are running. This is followed by another separator : which is being followed by ~ and $ signs respectively. Here the ~ sign refers to the Home directory of the particular user this means the terminal is current opened in the Home directory of the user having username “sarthakpranesh”, whereas the $ symbol means that the terminal session is a regular session and not a root user session ( a root user terminal window would have a # instead ).

Whats a Home directory ?

Each user in a Linux based operating system has there own Home directory assigned to them by the operating system. This allows different users to install applications that are specific for them and store information that they don’t want to share with other users on the system.

What is a Root User ?

A Root user has special system privileges and admin rights. This user is the default user and has access to all commands and files on the Linux system. It is not advised to perform commands as a Root user unless and until extremely necessary.

Man command

I believe this to be the most important command of all, it displays the documentation/manual for a command in the terminal itself.

Try running the following in your terminal to get the documentation for the man command

man man

On running the above command you’ll be shown the following in your terminal

You can scroll down in the terminal windows and read more about Man command in Linux

To exit the documentation press q on the keyboard and the documentation will be closed. The man command comes in handy when you aren’t sure about how to use a command or need to look up all the options or functionality it offers.

LS command

This command is used to list the current directory contents. For example — let’s say we are in a directory that contains 4 files and folders in total, then on running ls it will list all non hidden files and folders in that directory. Like any other command in Linux, the ls command also has a bunch of options you can use.

Here is the output if you run ls on your default Home directory ( hence default directory when terminal is opened ). You’ll see some common sub directories listed here like Documents, Downloads, etc.

You might see a bit different output depending upon your use of the system. Here you can also see how I have user specific folders and applications installed that won’t be available to other users on my system

Some common ls command options are as follows

  • ls -a — the -a option lists all files and folders present in the current directory, even those which are hidden.
  • ls -l — the -l option lists all not hidden files with extra information like file permissions, owner, size, date and time of creation or last modification, etc.

Try running man ls to see documentation for ls command and give a few options a try.

CD

This is not a command but a very useful tool. The cd tool is baked into your shell and allows you to change your current directory in the terminal window. Also you can not use man cd to get the documentation for the cd tool as it is not a command but a feature baked in your shell itself.

Remember the Downloads sub directory in your home lets cd into that directory and list all files using ls command.

Pay attention to when you run “cd Downloads”, you’ll observe that “~” changes to “~/Downloads” informing us that we are now in the Downloads sub directory. Now if you run “ls” you can see all your files in the Download directory.

TOUCH command

This command can be used to create a empty file in the current directory from the terminal. Let’s say we want to create a text.txt file in our downloads folder. For doing so we run the following command in the terminal window and then later on verify the creation of the file using ls command — touch text.txt

We run “touch text.txt” to create the file and then use “ls” to list the files and sub directories to verify the creation of the file.

MKDIR command

This command is used to create sub directories. Let’s try to make a sub directory called games in our user’s Home directory. Run the following for doing so — mkdir games

clear command

When you use different commands on the terminal it becomes kind of obvious that after a while you’ll have many outputs on the terminal window and you’ll want a completelly clean screen again. This is where the clear command comes in.

To get a clean terminal screen back just run the following on your terminal — clear

PWD command

This command is used to print out the name of the current working directory your terminal is present in. Let’s say we still happen to be in our downloads folder then on running pwd in the terminal it will show a absolute path for our current directory which is Downloads sub directory.

Make sure you are in your “Downloads” folder or “cd” into it first

This tool comes in real handy when you need the absolute path to a sub directory.

WHO command

This command helps you see the users that are currently logged into the system. To see users currently active and logged into the system just run the following in your terminal — who

Here you can see my current user’s username “sarthakpranesh” being showed because off course I am logged into the system. Other details are shown as well like the time and date when the user last logged in.

Another similar command would be whoami which prints out the username of the current user.

Quite simple right ?

ADDUSER command

As the name suggests, this command helps you add a new user to your system. For doing so you’ll need root permission which you can get access to by running the command with sudo .

For adding a new user named test to your system run the following

sudo adduser test

On running the above command you’ll be prompted to enter your password, make sure you enter it correctly and press enter ( the password you enter will not be displayed on the screen for obvious security reasons ). After doing so the system will ask you to provide relevant details for the new user, fill in those details and press enter. In the end the command will ask you if the information entered is correct or not, press y and enter if correct or else press n .

On pressing y the new user will be created, you can now log out and see the new user being displayed in the login screen. When you login as the new user you’ll experience a completely fresh new version of your operating system. This is because the new user does not have your user specific changes that you made in your user account ( hence the new user has a new Home directory for itself ).

DELUSER command

This command can be used to delete any user from your system. Also requires root level permissions/privileges, for which we will use the sudo command.

Let’s delete the user that we made earlier. In the terminal run the following command, enter your password and press enter

sudo deluser test

We see here the terminal says removing user ‘test’ and goes on to remove the user. Also, look how the terminal does not ask for password this time! When you enter password once in the terminal it remains till 15mins and you don’t have to re-enter till timeout

Please be careful when you deal with users, you don’t want to delete a important user ( or yourself from the system ).

FIND command

Something to showoff huh

This command lets you search for files in your system in the terminal itself. For achieving this we simply do file filename.extension . This command also takes in regular expressions as filename.

Lets test this command by creating a file called text1234.txt in Home directory and then running the find command like below

Here we use the touch command to create the file, use ls to verify it’s created or not and then use find command to find the file ( Here asterisk is used as regular expression, so text* means any file that is starting by the name text)

RM command

Last command we’ll cover in this tutorial, this command is used to help delete unwanted files or directories from the system. Let’s delete both the text.txt and text1234.txt that we created earlier in the tutorial. For doing so we run the following command — rm text.txt text1234.txt

You can use ls command to verify the deletion of the files.

Please be super careful while running the rm command, this command is very powerful and can delete your whole Linux setup as well.

Summary

Linux is a Unix like operating system and a kernel. The shell provides the user a way to communicate to the kernel. There are a lot of commands that can be performed using the terminal of a Linux based system. Use the man command to find out more about these commands and try out different options and sets of options.

As we can see Linux is pretty simple and fun to use, you just need to know commands that will allow you to use it to its full potential. We’ll cover more commands and technical concepts like Linux File System, File permissions, Package managers, etc in the coming parts of this tutorial. Till then happy learning :)

--

--

Sarthak Pranesh
VIT Linux User Group

Full Stack | React Native | Gopher | Open Source and Linux Enthusiast | Indian | Hindu