Skip to content

Command Line Interface

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage files and configure the computer. It is one of the oldest and most powerful ways to interact with computer systems.

We will extensively use the command-line interface to

  • Trigger automated test execution on a remote server
  • Generate automated test execution reports
  • Change automated test execution schedule details
  • Change test framework configurations



› CLI and Computer System

Any computer, whether desktop, laptop, or smartphone, is a collection of electronic devices that stores, manipulates, and renders data. Regardless of the computer systems, there are generally 3 ways to interact with them.

The first way is through the command-line interface, which we will learn in great detail in this module.

Expand to see Command Line Interface info
  • text based user interface
  • user types desired command
  • computer runs the chosen command
  • result is displayed as text

The second way is through Graphical User Interface, which every computer system currently in the market utilizes as the default interaction mode.

Expand to see Graphical User Interface info
  • graphical based user interface
  • user interacts with visual components on screen
  • computer runs the program based on user interactions detected
  • result is displayed as interactive visual components

The third way is through Natural User Interface, which lets the user interact with their computer system using their natural behaviors such as voice commands, hand gestures, and facial expressions.

Expand to see Natural User Interface info
  • natural behvaior based user interface
  • computer analyzes the user behavior and responds by running selected program
  • result is relayed as a feedback to the specific user senses ( eyes, ear, skins etc)



› How CLI Works

Every computer system provides the following components to support Command Line Interface.

  • terminal
  • bash
  • commands ( program )

The relationships of these components can be expressed in the following diagram

From the diagram, the terminal is a window or a tool that allows the user to type a command and as well as see the result of the command execution. In comparison, the bash is a specialized translator tool that interprets the command typed by the user and relays that to the computer system. Once the command is relayed, the computer will execute the program associated with the command and relays the result to the terminal for a user to see.

Try this command in your computer:

curl -X GET https://api.chucknorris.io/jokes/random | json_pp

In the above example, you were able to type the command using the terminal. The command you typed were understood and recognized as legitimate by the bash, and the computer executed the corresponding program, and the result was displayed on the terminal.

If you accidentally enter a command that bash does not recognize, it will throw a 'command not found' error.



› Commands

It is a program that is globally accessible in your computer system. When you type a command in a terminal, a bash will scan your computer for a globally accessible program that matches the name of the command you have typed. In our training, we will cover the following set of commands:

List of commands

    pwd:   show me the file path to current folder 
    ls :   display the current folder cont 
    cd :   change the current folder location  
    mkdir: make a folder 
    rmdir: remove the folder 
    touch: create a file 
    rm   : remove a file 
    mv   : move a file 
    cp   : copy a file 
    nano : edit a file 
    cat  : show me the content of a file 
    head : show me the top of the file
    tail : show the bottom of the file 
    git  : start tracking the files 
    start: open the folder in windows file explorer
    open : pen the folder in mac file finder

As you might have noticed, the majority of the commands we will learn is something to do with files. This is because almost everything on your computer is a file. Therefore, it is especially important to understand what exactly the file is.



› File

In your computer system, everything is represented as a file. The only thing that is not a file is a process (running program) and underlying hardware. Some stuff that is just a file includes:

  • folder
  • mouse pointer
  • desktop
  • taskbar

The computer uses a file to store data. Every file in a computer has its type and its associated modes ( attribute ).

Type Mode Example
Directory ( folder ) container or organizer Picture folder
Binary executables, program Google Chrome
Text storage Picture, Video, Music

More specifically, a file is just a block of memory with a title tag on the Hard disk drive. Everything you have on your computer, including installed programs, pictures, and even operating systems, is stored physically in a hard disk drive.

You can directly view and interact with this hard drive disk through your File System software.

Example of File System software from Windows

File Explorer allows you to manage the Hard Disk Drive content.

When you log into a computer, you log into a specific folder on your Hard Drive. This folder location is known as Desktop. From this location, using the file system software, you can reach any files on the hard drive using a file path.



› File Path

A file path shows where a file, a folder, or other item is located on the hard drive. Let's look at one of the examples.

The figure above shows the unique file path for the Moonlight.mp3 music file. The file path always starts with the root folder and is followed by parent and sub-folders until the target file is located. Then, a backslash (\) and forward-slash (/) are used to separate these parent sub-folders and a file. Finally, a file path always ends with the name and extension of the target file.

With this brief review of pre-requisite topics, we now can dive into learning commands that Software Engineer in Test uses in their daily testing development activities.