The Command Line Interface

In this lesson, we’ll discuss the basics of perhaps the most important tool in your belt as a programmer: The Command Line

We’ll cover the following

  • What is the terminal?
    • Listing files and directories
    • Checking what directory you are in
    • Changing directories
    • Reading files
    • Creating files
    • Creating a new directory
    • Moving files
    • Removing files

What is the terminal?

The command-line interface is a tool into which you can type text commands to make the computer perform specific tasks in contrast to using a graphical user interface through pointing and clicking on menus and buttons with a mouse.

Since the command line interface allows you to control the computer directly by typing commands, many tasks can be performed more efficiently. For example, if you want to make one change in the names of around 2000 files, you can use a for loop on the command line and change the names of all of them in a few seconds. Therefore basic knowledge of the command line is an absolute essential.

The user interface that accepts typed commands and displays data on the screen is called a shell. There is a wide variety of shells that you can choose from, but the most common is the Bash shell, which is the default on Linux and Mac systems in the Terminal application. Windows systems only include the anemic Command Prompt application by default, which is nowhere near as powerful as Bash. If you’re going to follow along on your windows machine, however, consider installing cygwin.

Open up a shell; you will see a blank (usually black) screen with a cursor to the right of something like:

accountname@machinname:~$

Let’s finally look at a few commands now!

Listing files and directories

Type ls into a shell and hit enter (or try it below!) and watch the magic happen.

ls

Voila! All the files and directories in your current directory get printed.

Checking what directory you are in

Also, to check what directory you are currently in, type pwd, and hit enter. Here is an example:

pwd

Changing directories

You can change to a directory that exists within your current directory with the command,

cd nameOfDirectory

you can move back to a parent directory with the command,

cd ..
ls
cd sampleDirectory
ls
cd ..
ls

Reading files

You can print files to the terminal with the command,

cat nameOfFile
cat SampleFile.txt

Creating files

touch command can be used to create a new file. It will create and open a new blank file if the file with a filename does not exist. And in case the file already exists then the file will not be affected.You can create empty files with the command,

touch nameOfFile

Creating a new directory

You can create a new directory with the command,

mkdir newFolder

Moving files

mv command could be used to move a file from source to destination. It will remove the file filename from the source folder and would be creating a file with the same name and content in the destination folder.You can move files from one directory to another like so,

Removing files

rm command could be used to delete a file. It will remove the filename file from the directory.

Now that we know some command line basics, let’s move on to learning version control with Git in the next lesson!

Also Read – An introduction to Software Stacks


That’s it!
You have successfully completed the post. Do Share : )

Peace Out!

One comment

Leave a Reply

Your email address will not be published.