Command line Interface (CLI)

Lord AbiollaLord Abiolla
6 min read

CLI is the short form for Command Line Interface.

It is a text-based way of using your computer i.e. instead of an interface where you can click buttons, menus, etc using a mouse, you type commands and the computer responds.

CLI is referred to as the Command Prompt on Windows and Terminal on macOS and Linux.

Why use CLI?

CLI is the most ancient way of interacting with computers before the development of GUI (Graphical User Interface) dating back from the development of Unix Operating Systems.

Some of the reasons why people, especially developers would use CLI are as follows;

  1. Speed: CLI is faster and quicker at doing things compared to GUI. In the terminal, you type commands and press Enter and quickly an output is displayed unlike GUI where you have to click around to find folders etc.

  2. It helps one stay organized: Creating folders and files in CLI is done in short commands without having to switch between app like in GUI.

  3. CLI works everywhere: CLI can be used in running servers, installing software, used in version control, and to build projects while some of the aforementioned things cannot be done on GUI.

CLI vs. GUI

FeatureCommand Line InterfaceGraphical User Interface
Interface typeType commands in text interface.Click buttons, menus, icons, etc.
Memory requirementsLow memory requirement.High because of graphics and animations.
Speed and efficiencyIt’s faster once you learn the basics.It’s slower for repetitive tasks.
What you needDeveloper just needs a keyboard.You need a keyboard and mouse.
How it feelsIt feels like giving instructions.It feels like exploring with a mouse.

Accessing the CLI

  1. Windows

    a). Press Windows Key + S

    b). Type Git Bash (if installed) or cmd

    c). Click to open it.

  2. macOS

    Option 1:

    a). Open Finder

    b). Go to Application > Utilities

    c). Open Terminal

    Option 2:

    a). Press Command + Space

    b). Type Terminal

    c). Press Enter

  3. Linux

    a). Press CTRL + ALT + T or search Terminal from App launcher.

N/B: A Shell - This is a program that takes the user commands typed on the CLI, calls the operating system to run these commands to interpret them and give an output.

Git

It’s almost agreed universally in software development world that the best developer experience comes from unix-based operating system. That doesn’t windows is bad though.

For this reason, let’s learn how to install Git Bash in order to have that experience on our windows machine.

Git Bash is a terminal application that brings unix styled command line to Windows. It is not a full Linux system, but it gives you access to many of the same tools and behaviors while running on windows.

How to install Git

  1. Go to git website. Git download link

  2. Download the Git Windows installer.

  3. Open the installer and follow the set up prompts.

  4. Finish installation and you’ll have Git in your Windows computer.

Basic Unix Navigation

When you start the terminal, you will see a text display called prompt waiting for your input. Note that your current directory/folder will always be your home directory represented by the tilde symbol (~)

To look around, find files and directories within your home directory, use the ls command which stands for list. it lists contents of the current directory.

To make a new directory/folder, use the mkdir commands followed by the name of the new directory and press Enter. For instance, lets create a directory named css20. The command will be;

mkdir css20.

Now when you list the content of current directory again, you’ll notice the new folder called css20

Notice the new folder css20 that’s highlighted in the above image.

To move to a new directory/folder such that it becomes your current working directory, use the cd command which stands for change directory, followed by the directory name. For example. let’s move from our home directory to css20 directory using the cd command.

cd css20

Notice that the current working directory has changed from tilde(~) to css20.

Now to create a file inside the css20 directory, we can either use touch to create an empty file or a text editor called nano or vim. The choice is yours but for now, lets use touch to create empty file called homework.

touch homework

After creating the file, when we ls, we can see the homework file inside the css20 directory.

If you no longer needs a file and wants to delete it, we the rm command followed by the file name as shown

rm homework

homework file no longer exists inside the css20 directory after ls command.

However, to delete a directory, we use the rm command plus a -r to mean we want to delete the directory and all its content recursively as shown below;

rm -r css20

Here are tables of unix commands and what they do:

  1. File and directory management.

CommandDescription
lsList current directory contents.
pwdShows current working directory.
cd [directory name]Change directory
mkdir [directory name]Create a new directory
rm -r [directory name]Deletes a directory recursively.
rm [file]Delete a file.
cp [source] [destination]Copy a file or directory.
mv [source] [destination]Move or rename a file.
  1. File content commands

CommandDescription
cat [file]Display file content
more [file]View file content page by page.
less [file]Similar to more but with backward navigation.
head [file]Show the first 10 lines of a file.
tail [file]Show the last 10 lines of a file.
  1. Process management

CommandDescription
psDisplay active processes.
topShow real time process usage.
kill [PID]Terminate a process by ID.
killall [process_name]Kill all processes with the specified name.
  1. User and permission management

CommandDescription
whoamiDisplay current user.
whoShow logged in user.
chmod [permission] [file]Change file permission.
chown [owner] [file]Change file ownership.
passwdChange user password.

In conclusion, UNIX remain to be the most influential operating system in the software development world and the fact that it’s more secure, robust, and efficient makes it a better choice for servers, software development and networking.

11
Subscribe to my newsletter

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

Written by

Lord Abiolla
Lord Abiolla

Passionate Software Developer with a strong enthusiasm for data, technology, and entrepreneurship to solve real-world problems. I enjoy building innovative digital solutions and currently exploring new advancements in data, and leveraging my skills to create impactful software solutions. Beyond coding, I have a keen interest in strategic thinking in business and meeting new people to exchange ideas and collaborate on exciting projects.