April 8, 2019
April 8, 2019
What is CLI? To put it simply, CLI stands for command line interface. It is a program that allows users to type text commands instructing the computer to do specific tasks.
Despite being so powerful, the use of CLI hasn’t always been well-received. Beginners are reluctant to use it, thinking that it is only for advanced users. But, that is not true.
In this article, you will learn everything you need to know about CLI.
In the 1960s, CLI was used intensively.
Back then, people had only a keyboard as an input device and the computer screen could only display text information. The operating systems like MS-DOS used the CLI as the standard user interface.
Basically, users had to type a command on the CLI to perform tasks, as this was the only way to communicate with the computer.
After typing a command, the result users got would be either text information or specific action performed by the computer. That being said, typing the right command is the key.
If users type the wrong command, chances are they’ll end up deleting the wrong files or accidentally closing the program before saving their work. This is what people consider as the main drawback of using CLI.
Then, after years of only using a keyboard and risking to misuse the command line, the mouse was invented.
The invention of a mouse marked beginning of the point-and-click method as a new way to interact with the computer.
This method is much safer for average users, thus drove them away from CLI. But, later on, we will discuss that using CLI is better. Stay with us.
Apart from that, operating systems started to develop an attractive way of computing, using GUI (Graphical User Interaction). GUI itself was phenomenal because of the use of buttons and menus to represent specific commands. This approach has been proven to be very intuitive.
Today, GUI has become a common way of computing. However, most operating systems still offer a combination of CLI and GUI. For example, Mac users can either type “cal” in Terminal or click on a Calendar application to get the same results.
If we dive from CLI into the deeper part of an operating system, we will find the shell.
Shell is a user interface responsible for processing all commands typed on CLI. It reads and interprets the commands and instructs the operating system to perform tasks as requested.
In other words, a shell is a user interface that manages CLI and acts as the man-in-the-middle, connecting users with the operating system.
In practice, there are many things that shell can process, such as:
Among many types of shell, the most popular ones are Windows shell (for Windows) and bash (for Linux and MacOS).
The default shell in Windows is CMD.exe or the Command Prompt. In fact, Microsoft has used the Command Prompt since the old days, where MS-DOS was the main operating system.
To open the Command Prompt, you can click Start -> All Programs -> Accessories -> Command Prompt. Or, you can simply press Windows+R, then type CMD, and press enter.
Depending on what you need, type in either a single command or a combination. You can also type commands that run within a sequence (one command is executed after another).
The Command Prompt is so robust that it can manage many things within the Windows operating system:
Now, let’s learn how to use some syntax in the command prompt:
CD C:\Program Files
REN d:untitled.txt untitled1.txt
DEL /F untitled.txt
D:\ > LABEL d:MyData
Bash stands for Bourne Again SHell and was developed by the Free Software Foundation.
In Linux, Bash shell is one of many shells the Linux users can use. The other types are Tchs shell, Ksh shell, and Zsh shell.
In most Linux distributions, the shell is located under the Utilities menu. If you use Gnome desktop, the name is Terminal, but if you use KDE, the name is Konsole.
Meanwhile, in MacOS, the program is Terminal.app. To run this program, go to Application -> Utilities -> Terminal. Or, you can simply type terminal using Spotlight search.
Once the terminal’s opened, you can start typing a command. Basically, most commands consist of: the command itself, the argument, and the option.
While the command contains the instruction we want to perform, the argument tells where the command should operate and the option requests the modification of the output.
Now it’s time to learn how to use the shell.
To begin with, you need to know the syntax to deal with the shell. This is also known as shell scripting – ways of using the script in CLI to run certain tasks.
While there are many commands you can use with CLI, they all fall into two categories:
To understand the command syntax in MacOS, let’s learn from these examples:
mv ~/Desktop/untitled.rtf ~/Desktop/untitled1.rtf
Again, typing the right command is important. That means you should pay attention to each character you use, including space. Not only that, make sure you type the correct case.
If for certain reasons you want to stop the ongoing process on the Command Prompt or Bash, simply hit Control+C.
As previously mentioned, the GUI was developed within the operating system as soon as the mouse became a new input device to operate the computer.
We should admit that GUI is visually attractive and easily understood. But, for some tasks which are vital, CLI is way more powerful.
Here, we would like to pick some points why you would use CLI over GUI. However, we leave it to you to choose depending on your type of work.
To give you an illustration, there is a method called PSD to HTML in website development.
In PSD to HTML, the process starts with making a mockup in Photoshop. The Photoshop Document (PSD) is then converted to HTML.
W3C compliance will ensure that the website has good code to make it compatible with all browsers.
So, understanding the code is vital to understand the core process.
The same thing goes for CLI in the operating system. While the GUI may seem appealing, CLI is light, powerful and straightforward.
Despite a long debate that CLI is only for the experts, you have now learned it is for average users as well.
The fact that most operating system still provides CLI along with GUI proves that CLI is crucial. Also, using CLI gives more positive points than GUI because:
Now, let’s get the job done using CLI!