FUNDAMENTALS A Complete Guide for Beginners
CLI is the abbreviation for Command-Line Interface. In Linux or other operating systems, you normally use your mouse cursor to explore through the OS and you also interact with the machine with the help of the mouse. CLI in Linux gives you an alternative way.
Using CLI you can provide the machine with written commands to do something. Now from the sound of it, it sounds tiring to do something with written commands which can be done with just a click of the mouse. However, CLI has its importance in the computer world, especially in Linux. CLI in Linux is a text-based interface that helps us in interacting with the machine.
Brief History of CLI
Now if you want to learn about CLI in Linux then you should know how and why command lines were used. In this section, I will give you a little preview of that. In the early days of computers(1960-70) people started using multiple applications and a single machine was used by multiple users. It became difficult to keep control over all the user data and applications.
So, there came shell an intuitive and graphical way to control your machine. Shell is what you see in your computer or touch screen mobile these days. But Shell wasn’t used to be graphical, it was text-based. Where a user will write some commands and get appropriate responses. Over the years the Graphical Interface of the Shell has changed but the CLI underneath remains the same. Here is what CLI looks like. Here it shows the current month of the calendar. Normally what you would do is move your mouse cursor to the calendar icon and click it.
Types of Command Interface
There are three types of Command interfaces.
- Command Line Interface.
- Graphic User Interface.
- Menu-Driven Interface.
Graphical User Interface
GUI also known as Graphical User Interface is the most used Command interface these days. GUI uses graphical icons to indicate locations on your machine and also uses graphical icons to navigate through the operating system.
Menu-Driven Interface
Menu-Driven Interface is based on giving you a menu so that you can navigate through your device. It helps you access folders, open applications, and all the other things you might need to do on your device. Now the best example of a Menu-Driven Interface is the mobile phone in your hand.
If you look at it carefully your mobile phone always gives you a list of options or a menu. And from the menu, you select which application to open, what file to download or remove, etc.
Difference Between CLI and GUI
CLI stands for Command Line Interface and GUI stands for Graphical user interface. In the early days of technology and software, there was only Command Line Interface. But as technology advanced with time, it was necessary to make computer machines more mainstream and user-friendly.
CLI wasn’t very user-friendly as people without programming knowledge found it hard to use it. So developers created GUI, which was more user-friendly. It was easy for beginners too. Because GUI doesn’t need a user to have any idea of how the Command Interface works. There are some key differences between CLI and GUI.
The main difference between CLI and GUI is Command Line Interface requires the user to provide a text command or a series of text commands, but the Graphical User Interface doesn’t require the user to do something so complicated, the user just needs to click on the appropriate graphical icons.
Why Use CLI Over GUI?
Now at first glance, you would think GUI is better and CLI is boring. Well, you are somewhat right. Compared to GUI CLI is boring. But there is some use case that is easier to do with CLI than GUI. In this section, I will try to show you some cases where we use CLI and why we use CLI.
CLI is faster than GUI. Now you might think how? Then take a look at the picture that I have given below. Here I have created a file using just one Command Line. I even named it while creating it. But if I were to create a file using GUI I would need to follow some steps.
Steps to Follow >
➊ Open your text editor.
➋ Write your content.
➌ Press CTRL+S.
➍ Save the file name as file1.txt and press ENTER. Now you tell me which one is easier. Using just one Command Line or using multiple long steps with GUI. It should now be obvious to you why there are times that you should use CLI. if it’s still not obvious to you then let me show you another example. I have created four folders with just a single Command Line which is impossible using GUI. if you want to create four folders with GUI you will do this-For four times. Which is more time-consuming than Command Line.
- The user interface which uses CLI requires less RAM than the interface which uses GUI and less memory is required for CLI. So, using the Command Line interface makes the machine faster.
- You can use CLI on machines that are fairly less expensive and have weaker hardware, for using GUI machines must have a certain amount of good hardware.
What is Shell?
Now in the second section of this article, I have mentioned SHELL. So what is a SHELL? This is what I will try to explain in this section.
There are many types of shells. But I will only discuss Bash Shell. Because this is the shell that is widely used in Linux Distributions. So Bash Shell is the interface where you will write the Command that you want to execute. So, in easy words, the Terminal is a Shell. Look at the picture below. I used the command echo in my bash shell to print out an argument. So, this is what generally shell in Linux Distribution looks like. Now while we are at it, let’s look at what a shell looks like in the Windows system. Shell in Windows system is called PowerShell. Take a look at the below picture. This is Windows Shell. Most of the command lines are actually the same in these two shells.
How to Start Using CLI as a Beginner
Starting to use Command Line on Linux might look scary at first. But by following proper steps and knowing the right CLI Commands you can easily start using the Command line to execute operation Linux Distribution systems. Here I have used Ubuntu Distribution to demonstrate.
Follow the steps that I am showing. Then you will be able to open the Ubuntu terminal and run commands.
Steps to Follow >
➊ First open your machine that has Linux Distribution Ubuntu installed. It could be natively there or you can use a Virtual Machine.
➋ Then go to your Desktop and right-click on your mouse, there you will see Open in Terminal click on that.➌ You will see the terminal pop up. The prompt will show the name of the user and the name of the machine (the name you provided while installing Ubuntu).➍ You are ready to execute your first Command. Write the below command and hit ENTER to test out the terminal. Later I will show you more Examples.
touch file1 file2
➎ You will see that this command created two files on your desktop. So this is how you can open the terminal and start using CLI for executing commands on your machine. In the next section, I will give some more examples of using CLI.
Examples of CLI
In the previous sections, I have shown you some examples of using CLI. Now I will show you some more examples. Remember these will be pretty basic examples as I am trying to make you comfortable with CLI.
pwd
This command shows the current directory that you are in. Now to execute this command follow the given steps.
Steps to Follow >
➊ Open your Ubuntu Terminal.
➋ Write the command below:
pwd
➌ Press ENTER.
Output >
Showing that I am currently on my Desktop.
cd
This command lets you jump into a directory. I previously created a directory named hello inside Desktop. Now I will access that directory using cd. Follow my steps.
Steps to Follow >
➊ Open your Ubuntu Terminal.
➋ Write the command below:
cd hello
➌ Press ENTER.
Output >
** ls command shows the list of contents in a directory.
rm
This Command is used to remove files. Write this command to delete file1 and file2.
Steps to Follow >
➊ Open your Ubuntu Terminal.
➋ Write the command below:
rm file1 file2
➌ Press ENTER.
Output >
These are some of the basic commands. Get yourself started on CLI with commands like these.
Conclusion
In this article, I have tried to give a brief overview of CLI in Linux. Command Lines are such that it feels bothersome at the beginning. But if you want to be a good software developer or a data scientist you must have a good grab on the concept of the command line. And on top of that CLI is more secure than GUI. After going through this article you will be familiarized with the basics of CLI in Linux. If you want to know more about the command line you can see this article Bash and Alias.
Similar Readings