What is the Command Line?

What is the Command Line Interface (CLI)?

A command-line interface allows the user to interact with the computer by typing in commands. The computer displays a prompt, the user keys in the command and presses enter or return. In the early days of personal computers, all PCs used command-line interfaces.


Features of a Command Line Interface (CLI):

Commands must be typed correctly and in the right order or the command will not work.
Experienced users who know the commands can work very quickly without having to find their way around menus.
An advantage of command driven programs is that they do not need the memory and processing power of the latest computer and will often run on lower spec machines.
Command driven programs do not need to run in Windows.
A command-line interface can run many programs, for example a batch file could launch half a dozen programs to do its task.
An inexperienced user can sometimes find a command driven program difficult to use because of the number of commands that have to be learnt.


Advantages and Disadvantages

There are also many Advantages and Disadvantages over the use of the Command Line, these include:


  • Requires fewer resources
  • Concise and powerful
  • Expert-friendly
  • Easier to automate via scripting


  • Commands not obvious
  • Not very nice looking, isn’t very appealing
  • Not very Friendly for Beginners
  • Very easy to make dramatic, unreversible changes to your PC


How do I actually use a CLI though?

Basic Commands

When you open a Command Line Interface, by default you are in the home directory of the logged in user. You will see the name of the logged in user followed by the hostname. $ means you are logged in as a regular user, whereas # means you are logged in as root.

Unless you are performing administrative tasks or working inside root directories never work as root as it will change the permissions of all directories and files you worked on, making root the user of those directories and their content.

You can list all directories and files inside the current directory by using the ls command. e.g:

yourname@yourhost: ~ $ ls
Desktop Documents Downloads Music Pictures Public Templates Videos


Moving around the Directory

To change to any directory, use the cd command. Use forward slash to enter directories. So if I want to change directory to ‘Downloads’ which is inside my home folder, we run cd and then give the path. In this case ‘yourname’ is the username. You need to type your username:

yourname@yourhost: ~$ cd /home/Downloads/
yourname@yourhost/Downloads: $

As you can see in the third line, ‘Downloads’ directory has moved to the end of the address, which denotes that currently we are inside this directory. I can see all subdirectories and files inside Downloads directory by running the ls command. You don’t have to give the complete path if you want to move inside the sub-directory of the current directory. Let’s say we want to move inside the ‘Test’ directory within the current ‘Downloads’ directory. Just type cd and the directory name, in this case it’s ‘Test’.

yourname@yourhost/Downloads: $cd Test

If you want to change to another directory just follow the same pattern: cd PATH_OF_DIRECTORY . If you want to move one step back in the directory then use cd . . /. To go back two directories use cd . . /. . / and so on.

But if you want to get out of the current directory and go back to home, simply type cd.


How do I Create and Delete a Directory?

Creating a Directory

If you want to create new directories the command is mkdir. By default the directory will be created in the current directory. So give the complete path of the location where you want the directory to be created:

mkdir /path-of-the-parent-directory/name-of-the-new-directory

So if I want to create a directory ‘documents’ inside the ‘Downloads’ directory, then this is the command I will run:

[yourname@yourhost: ~$ mkdir /home/yourname/Downloads/documents


Removing a Directory

If you want to delete any file or directory the command is rm (for files) and rm -r (for directories). You need to be very careful with this command because if you fail to give the correct path of the file or directory then it will remove everything from the current directory and you may lose precious data. The command is simple:

rm /path-of-the-directory-or-file


Closing Thoughts

I quite like using the CLI, I just feel it looks a little out-dated and boring if there is no theme or customisation applied. Sometimes the only way to complete a particular task is to use a Command Line Interface, so it’s best to customise it how you want to make it more enjoyable to use.

As long as you’re careful and know what you are doing, it can be the best and most powerful application on your computer.