Magic in the Shell: A Deeper Look at the Command Line Interface (2023)

Magic in the Shell: A Deeper Look at the Command Line Interface (1)

The longer I gaze into the crystal ball of knowledge, the more I realize there’s more to learn than I could in this lifetime.

The worlds of technology, mathematics, psychology, and science are colliding in ways I never imagined. The topics I’ve unearthed are creating parallels that would’ve been impossible to discover on their own.

Learning the fundamentals of networking and operating systems has allowed me to better understand how to use command-line tools and make server requests. Understanding how the mind works has allowed me to make analytical decisions instead of emotional ones while problem-solving.

This week’s journey took an unexpected turn while learning about command line interfaces. I found myself asking the philosophical question: “What kind of magic happens when I execute this command?” I’ve been using CLI tools for most of my life, but I never took the time to truly understand what was going on behind the scenes.

Until now.

Magic in the Shell: A Deeper Look at the Command Line Interface (2)

Command Line Interfaces (CLIs) have a long history dating back to the 1960s. They were created as a way for users to interact with operating systems and perform simple computing tasks.

One of the very first CLIs was the Command Line Interpreter for the MIT Compatible Time-Sharing System (CTSS) developed in 1961. This was followed by the Multics shell, developed in 1965, which introduced many of the features that are still present in modern shells, such as command history and tab completion.

In the 1970s, the Unix operating system was developed. It’s the parent to many of the modern operating systems we use today like macOS and Linux. Unix featured the Bourne shell (sh) as its default CLI which became the foundation for many other shells developed in the following decades, including the C shell (csh), the Korn shell (ksh), and the GNU Bourne-Again shell (bash).

In the 1980s and 1990s, personal computers and graphical user interfaces (GUIs) led to a decline in CLIs. However, these interfaces remained popular among developers and administrators due to their flexibility.

CLIs are widely used in many areas of computing such as:

  • web development
  • system administration
  • data science
  • game design & testing

Many modern CLIs, such as the Windows PowerShell and the Azure Cloud Shell, have been developed to make it easier for users to interact with operating systems and perform network tasks like SSH.

Magic in the Shell: A Deeper Look at the Command Line Interface (3)

With a better grasp of CLIs, we can start to understand what exactly happens when we use them. The easiest way to do that is by thinking of them in two parts; the terminal and the shell.

The shell acts like the brains of a terminal application. It takes the string you enter as a command and parses it into an executable. It allows a user to navigate the files of an operating system, run programs, start scripts, and perform other tasks on the computer.

(Video) The Mythical CLI Command Line Interface, OHH My! – Todd Echterling

In Unix-based systems, such as Linux and macOS, the default shell is often set to Bash (Bourne Again SHell), but there are other options like Zsh and Fish. The terminal provides an interface that allows the user to type commands, the shell executes them and allows you to view the results.

Without a shell, your terminal would be closer to a word processor than a mighty programming tool.

Magic in the Shell: A Deeper Look at the Command Line Interface (4)

Harnessing the power of a shell allows you to do some pretty amazing things. Here’s an example:

The macOS terminal allows you to use a wide variety of Linux-style commands. One of my favorites is cat (concatenate.) It reads data from a file and gives its content as output.

Magic in the Shell: A Deeper Look at the Command Line Interface (5)

The command takes one or more filenames as arguments and displays the contents of each file:

Magic in the Shell: A Deeper Look at the Command Line Interface (6)

That’s a lot of code to look at in the terminal!

If you wanted to know how many lines of code, you could tell the shell to execute a second command after receiving the output from cat.

You can accomplish this by using the pipe | character following the filename:

Magic in the Shell: A Deeper Look at the Command Line Interface (7)

Then use another one of my favorite commands, word count (wc) following the pipe:

Magic in the Shell: A Deeper Look at the Command Line Interface (8)

The wc command is used to find the number of lines, words, and bytes in the files specified in the arguments:

(Video) Jenkins Beginner Tutorial 4 - How to use CLI (command line interface)

Magic in the Shell: A Deeper Look at the Command Line Interface (9)

Now we can see that the index.js file from my last blog project has 91 lines of code, 327 words, and 3046 bytes.

Magic in the Shell: A Deeper Look at the Command Line Interface (10)

When a command is executed in the terminal shell, it goes through a series of steps before the command is completed. The process begins when the user types a command and hits enter. The terminal shell then interprets the command and checks to see if it's a built-in command or an external command.

When you execute a command in the macOS terminal, the following steps happen:

  • The terminal interprets the command and checks if it’s a built-in command or an external command.
  • If the command is a built-in command, such as ‘cd’ or ‘pwd’, the terminal will execute the command directly, without the need to spawn a new process.
  • If the command is an external command, the terminal will check if the command is in the system’s PATH. (The PATH is a list of directories that the terminal checks for executable files.)
  • If the command is found in the PATH, the terminal executes the command by spawning a new process. If the command is not found in the PATH, the terminal will return an error message indicating that the command could not be found.
  • When a new process gets spawned, the terminal creates a new process object and assigns it a unique process ID (PID). (The process object contains information about the command, its arguments, and the environment it’s running in.)
  • The terminal then passes the process object to the operating system’s process scheduler, which assigns the process to the CPU for execution.
  • Once the process is executed, the terminal will wait for the process to complete and then return the output to the user. If the command produces any error, the error message will be displayed in the terminal.

To find a list of processes with the macOS terminal type:

ps -ax

Magic in the Shell: A Deeper Look at the Command Line Interface (11)

To end any process on the list type kill PID#

Magic in the Shell: A Deeper Look at the Command Line Interface (12)

Learning to use these tools will help you navigate challenging situations throughout your career.

The PATH variable was a particularly difficult monster for me to tame while attending Bootcamp. Installing Node.js with homebrew (instead of using npm install -g) created some major issues with the PATH location for my project dependencies on an M1 MacBook. Connecting to a PostgreSQL database with Ruby on Rails forced me to find and kill many processes while attempting to deploy to Heroku.

With a deeper understanding of CLIs, you can truly appreciate the hidden world that exists on the other side of your enter key. The invisible processes powering each request are vital to the tasks we rely on each day.

The next time you type “cd” or “ls,” think of how far we’ve come from the early days of the command line interface and how these tools continue to be simple solutions in a complex world.

https://nodejs.org/dist/latest-v18.x/docs/api/process.html

https://www.postgresql.org/docs/

https://en.wikipedia.org/wiki/Compatible_Time-Sharing_System

https://byjus.com/gate/difference-between-unix-and-linux/#:~:text=Basic%20Definition-,Linux%20is%20an%20open%2Dsource%20operating%20system.,the%20user%20and%20the%20computer.

FAQs

Is command line interface a shell? ›

A command-line interface (CLI) is an operating system shell that uses alphanumeric characters typed on a keyboard to provide instructions and data to the operating system, interactively.

Which interface is known as the command line interface? ›

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.

What does CLI computer term stand for what is the purpose of it? ›

Abbreviated as CLI, a Command Line Interface connects a user to a computer program or operating system. Through the CLI, users interact with a system or application by typing in text (commands).

What are the types of shell commands? ›

1.1. Shell Commands
  • bg. put the most recently accessed job (child process) in the background. ...
  • cd. change directories. ...
  • echo. echo text to the terminal window. ...
  • fg. put the most recently accessed job (child process) in the foreground. ...
  • jobs. list processes started from current shell. ...
  • set. ...
  • setenv. ...
  • unset.

Which shells are available on command line interface? ›

Operating system command-line interfaces

Examples of command-line interpreters include DEC's DIGITAL Command Language (DCL) in OpenVMS and RSX-11, the various Unix shells (sh, ksh, csh, tcsh, zsh, Bash, etc.), CP/M's CCP, DOS' COMMAND.COM, as well as the OS/2 and the Windows CMD.

Why use a command line interface? ›

Using detailed commands through a command-line interface can be faster and more efficient than scrolling across GUI tabs and dialogs. This can be particularly powerful when handling highly repetitive tasks across many systems, and it demonstrates the advantages of a command-line interface.

What is command line interface short answer? ›

A command line interface (CLI) enables users to type commands in a terminal or console window to interact with an operating system. Users respond to a visual prompt by typing a command on a specified line, and receive a response back from the system.

What are the three types of command interface? ›

User interfaces may be of three types- command line interface, graphic user interface and menu-driven interface.

How does command line work? ›

The command line is a text interface for your computer. It's a program that takes in commands, which it passes on to the computer's operating system to run. From the command line, you can navigate through files and folders on your computer, just as you would with Windows Explorer on Windows or Finder on Mac OS.

What are the main features of a command line interface? ›

Following are some of the Command Line Features :
  • Command History. History option enables TL1 Agent to record all the commands which are executed in the history list. ...
  • Command Completion. ...
  • Command Line Editing. ...
  • List of Commands. ...
  • Complete Command Syntax. ...
  • Escape Key.

What are the 6 commands in cmd? ›

Windows Command Prompt Commands
  • Assoc. Most files in Windows are associated with a specific program that is assigned to open the file by default. ...
  • Cipher. Deleting files on a mechanical hard drive doesn't really delete them at all. ...
  • File Compare. ...
  • Ipconfig. ...
  • Netstat. ...
  • Ping. ...
  • PathPing. ...
  • Tracert.

What is a command-line interface quizlet? ›

What is the command-line interface? (CLI) A simple text based user interface for an OS.

What are the two main components of user interface? ›

graphical user interface (GUI) command line interface (CLI)

What is command line coding? ›

The command line (also known as the Terminal, or Command Prompt) refers to a type of program that comes pre-installed with Windows, Linux, and Mac computers and allows you to execute commands, run programs and navigate through the folders on your computer.

How do you write a command in shell script? ›

Steps to write and execute a script
  1. Open the terminal. Go to the directory where you want to create your script.
  2. Create a file with . sh extension.
  3. Write the script in the file using an editor.
  4. Make the script executable with command chmod +x <fileName>.
  5. Run the script using ./<fileName>.

What is a shell example? ›

The MS-DOS Shell, csh, ksh, PowerShell, sh, and tcsh are a few examples of shells. Unix is most frequently associated with shells because many Unix users choose to use the operating system's text-based user interface.

What is shell script with example? ›

A shell script is a text file that contains a sequence of commands for a UNIX-based operating system. It is called a shell script because it combines a sequence of commands, that would otherwise have to be typed into the keyboard one at a time, into a single script.

What are the 3 types of shell available in Unix? ›

Bourne shell ( sh) Korn shell ( ksh) Bourne Again shell ( bash)

How commands are executed in shell? ›

The basic shell operation is as follows. The shell parses the command line and finds the program to execute. It passes any options and arguments to the program as part of a new process for the command such as ps above. While the process is running ps above the shell waits for the process to complete.

What is command-line argument in shell? ›

What are Command-Line Arguments? Command-line arguments are parameters that are passed to a script while executing them in the bash shell. They are also known as positional parameters in Linux. We use command-line arguments to denote the position in memory where the command and it's associated parameters are stored.

What are 3 advantages of using the command line to control a computer? ›

The advantages of a command-line interface are:
  • greater control of an OS or application;
  • faster management of many operating systems;
  • ability to store scripts to automate regular tasks;
  • basic command-line interface knowledge to help with troubleshooting, such as network connection issues.
Dec 17, 2019

What are the 3 main advantages of using the command line over the GUI? ›

It requires less memory as compared to GUI. It generally uses a mouse to execute commands. The speed of GUI is Slower than CLI. Because the keyboard is used to execute the commands, the speed of the CLI is Faster than GUI.

When was command line interface used? ›

A command line interface or CLI is a method of interacting with a computer by giving it lines of textual commands (that is, a sequence of characters) either from keyboard input or from a script. They were originally developed for interfacing with computers over teletype machines in the 1950s.

What is the command-line interface called on a Linux system? ›

The Terminal is the platform or the IDE that provides the command line interface (CLI) environment to the user. The CLI terminal accepts the commands that the user types and passes to a shell.

Which of the following is not true about command line interfaces? ›

Which of the following is NOT true about command-line interfaces? They give you less control to manage detailed settings than a GUI.

What is the command-line interface called on a Linux system quizlet? ›

To make things easy, we will use the command-line interface in Ubuntu Linux, called TERMINAL.

What are the 4 types of interfaces? ›

There are four prevalent types of user interface and each has a range of advantages and disadvantages:
  • Command Line Interface.
  • Menu-driven Interface.
  • Graphical User Interface.
  • Touchscreen Graphical User Interface.
Sep 22, 2014

What are the 5 types of interface? ›

There are five main types of user interface:
  • command line (cli)
  • graphical user interface (GUI)
  • menu driven (mdi)
  • form based (fbi)
  • natural language (nli)

Which are 4 types of commands received by an interface? ›

An interface may receive four types of commands. They are control, status, data input and data output Control command: It is issued to activate the peripheral and to inform it what to do.

Why do hackers use command line? ›

A graphical user interface permits the user to interact with a computer by using a mouse or keyboard to control and make changes to visual elements on the computer's screen. Hackers enjoy working with a command line interface, such in Linux, because it gives them greater access over the system the exploit. Hackers have ...

What are some commonly used commands? ›

Commonly Used Commands
  • Option Commands.
  • Login / Logout Commands.
  • Copy Commands.
  • Create Commands.
  • Create Association Commands.
  • Delete Association Commands.
  • Delete Commands.
  • Detach Dimension Commands.

How many types of commands are there? ›

There are 3 main types of commands. DDL (Data Definition Language) commands, DML (Data Manipulation Language) commands, and DCL (Data Control Language) commands.

What are the three parts of the command structure? ›

All commands have three parts.
...
Let's take a look at each section of the command and explore how the command is structured today.
  • Command. The command (sometimes referred to as utility) comes first. ...
  • Flag. ...
  • Arguments.

What are the parts of a command line? ›

To review, the components of the CLI display are the prompt, the cursor, the input (text you have typed in), and the output of your commands and programs.

What are two 3 common methods to access the CLI? ›

Generally, you can access the CLI through a direct connection to the console port, or remotely using Telnet or SSH command.

How to find the wifi password using CMD? ›

Finding Wi-Fi Password
  1. Step1: Press start and type CMD, right-click on the Command Prompt option shown as a search result and click on Run as administrator.
  2. Step 2: Type netsh wlan show profile in the command prompt and press Enter to show a list of network names that we connect to.
May 25, 2022

How to get the password of WIFI using Command Prompt? ›

  1. Type and search [Command Prompt] in the Windows search bar①, then click [Open]②.
  2. In the Command Prompt window, type the command [Netsh wlan show profile name=”Wi-F name” key=clear]③, and then press Enter key. ...
  3. You can find the Wi-Fi password in the [Key Content] field in the Security settings category④.
Dec 30, 2021

Is Terminal A command-line interface? ›

Command line or CLI (command line interface):

In plain English once again, it's the space in which you enter the commands the computer will process. This is practically the same as the terminal and in my opinion these terms can be used interchangeably.

Is command-line interface A software? ›

CLI stands for command line interface. It is a program that allows users to type text commands instructing the computer to do specific tasks.

Is command-line interface A software interface? ›

Command line interface (CLI) is a text-based interface that is used to operate software and operating systems while allowing the user to respond to visual prompts by typing single commands into the interface and receiving a reply in the same way.

What are the three important parts of a user interface? ›

4 Key Elements of User Interface Design
  • Input Controls. This group of elements allows users to input information into the product. ...
  • Navigation Components. As the name suggests, this group of elements is used in navigating a website or an app. ...
  • Informational Components. ...
  • Containers.

What is the most important factor for a user interface? ›

Ease of Use, User Experience & Accessibility. One of the most important things to consider when choosing a user interface is about whether your users would be able to understand and make use of the interface. This is more than just if the interface is “easy to use”.

How to create a user interface? ›

Best Practices for Designing an Interface
  1. Keep the interface simple. ...
  2. Create consistency and use common UI elements. ...
  3. Be purposeful in page layout. ...
  4. Strategically use color and texture. ...
  5. Use typography to create hierarchy and clarity. ...
  6. Make sure that the system communicates what's happening. ...
  7. Think about the defaults.

What is an example of a command line? ›

The MS-DOS operating system and the command shell in the Windows operating system are examples of command-line interfaces. In addition, programming language development platforms such as Python can support command-line interfaces.

How do I use command-line interface? ›

Through the CLI, users interact with a system or application by typing in text (commands). The command is typed on a specific line following a visual prompt from the computer. The system responds to the text, and the user may then type on the next command line that appears.

How to use command line code? ›

Hold the special Windows key on your keyboard and press the "X" key. Choose "Command Prompt" from the pop-up menu. Hold the Windows key and press the "R" key to get a "Run" window. Type "cmd" in the box, and click the OK key.

Is Windows command line a shell? ›

Windows has two command-line shells: the Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.

Is command line same as shell script? ›

There is effectively no difference. The “shell” is software that lets you interact with your computer via a “command line” — a text-only, line-based, input feed. On Windows, there's “command.com” aka “the DOS shell” and “Powershell”.

Is C shell a Windows command line interface? ›

The C shell is a command processor which is typically run in a text window, allowing the user to type and execute commands. The C shell can also read commands from a file, called a script.

Is the shell also called a command-line interpreter? ›

The shell is the Linux command line interpreter. It provides an interface between the user and the kernel and executes programs called commands.

What is command shell used for? ›

A command shell is a text-based version of a file manager. So it is the equivalent of Windows Explorer on Windows, or the Finder on MacOS. At any given time it is open to a specific folder (or directory) on your computer. We call the folder that is currently open in the shell the working directory.

How do I open shell commands? ›

Opening a command or shell prompt
  1. Click Start > Run or press Windows + R key.
  2. Type cmd .
  3. Click OK.
  4. To exit from the command prompt, type exit and press Enter.
Sep 4, 2017

What is a shell in command-line? ›

What is a shell and why should I care? A shell is a computer program that presents a command line interface which allows you to control your computer using commands entered with a keyboard instead of controlling graphical user interfaces (GUIs) with a mouse/keyboard/touchscreen combination.

Is shell better than CMD? ›

Powershell is the advanced version of CMD with a lot of added functionalities and features. Moreover, it has a better graphical interface and better support for server automation tasks.

Is shell A programming language? ›

as with other programming languages, the shell language has the functionality to allow input & output, iteration, logical decision making, file creation and deletion, and system call capability. shell programs are free format, as long as the syntax of each shell command is correct.

What is difference between PowerShell and CMD? ›

Cmd is used primarily to execute batch commands, do some primary troubleshooting whereas PowerShell can be used for executing batch commands as well as administrative purposes. Scripts can also be written in PowerShell to automate the tasks. PowerShell also has an ISE which makes it easier to write and debug scripts.

Which commands are used in Windows command line interface? ›

This article lists the most important cmd commands under Windows.
...
Cmd commands under Windows.
cmd commandDescription
fccopare files and display the differences
mkdircreate a new directory
movemove/rename files
renamerename files
71 more rows
Oct 2, 2017

What is the command line interface for Windows? ›

The command line interface is a program on your computer that allows you to create and delete files, run programs, and navigate through folders and files. On a Mac, it's called Terminal, and on Windows, it's Command Prompt.

How the shell interprets the command line? ›

CONCEPT: The shell is a type of program called an interpreter. An interpreter operates in a simple loop: It accepts a command, interprets the command, executes the command, and then waits for another command. The shell displays a "prompt," to notify you that it is ready to accept your command.

What language is command line? ›

CMD is technically a shell scripting language like bash, sh, or csh. It's useful for automating tasks involving calling existing programs from the command line.

What is the command line called? ›

The command line, also called the Windows command line, command screen, or text interface, is a user interface that's navigated by typing commands at prompts, instead of using a mouse. For example, the Windows folder in a Windows command line is "C:\Windows>" (as shown in the picture).

Videos

1. How The Command-Line Can Give You Superpowers - Eric Fung - AndroidTO 2018 [Part of DevFest18]
(Intersect)
2. 7 Essential Command Line Tools (2022)
(Tech Craft)
3. Geospatial Data Magic At The CommandLine
(UC Denver FOSS4G Lab)
4. [Lesson 13] Introduction to the Command Line Interface - Jamf 100 Course
(Jamf)
5. Azure CLI Tutorial
(Adam Marczak - Azure for Everyone)
6. T205 Introducing DeepBlueCLI v2 now available in PowerShell and Python Eric Conrad
(Adrian Crenshaw)
Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated: 01/11/2023

Views: 5931

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.