An introduction to the GNU/Linux command line interface
March 19th 2016
The Linux command line interface, also known as the CLI is a powerful tool that interacts with the keyboard.
In this tutorial, you will find out about the basic terminal commands, we've included animated screenshots (GIFS) so that you can see the output of these commands.
The main advantage of using the command line is that you can run applications and commands really fast. You can use it to do pretty much everything you can do with the visual interface counterpart (GUI), and much more.
The commands that I will show you are available on any Linux machine and on most Macs.
Note: Even though the terminal looks like the Windows prompt command, these two are not the same, they are entirely different.
Why learn the command line ?
The command line is a must know for any web developer that wants to improve his skill set.
Most sites are hosted on Linux servers - this alone is enough of a good reason to start learning the terminal.
You need the CLI to start applications, set file permissions, use git, create cron actions, manage files and folders, find and replace text within multiple files at once, so on and so forth - all useful things.
Knowing how to use the terminal is a clear advantage at the workplace.
Let's dive in the most basic terminal commands!
Launch the terminal
One way of starting up the terminal is to search through the applications menu and simply click the terminal icon - no brainer.
However, there is another way to start the terminal, an easier one!
ctrl + alt + t and the terminal will launch. (in some rare cases this shortcut won't work - try the
win/super key and
t combination instead).
Must know terminal commands
Here are ten basic commands:
pwd # prints the path to the current directory ls # displays files and directories mkdir # creates a new folder cd # navigates between folders touch # creates new empty files cp # copies files rm # removes files mv # move and rename files man # displays manuals for different apps sudo # super user do, let's you run commands with admin privileges
Basic terminal commands and how to use them
Let's run the first command, a good start is the
Pwd stand for print working directory, this command will show you your current directory path.
If you are not sure where you are, you can write
pwd and you'll find out.
Let's get to the next command,
Ls is short for list, this command displays the file structure.
If you don't provide an argument for this command, it will automatically assume that you want to see the files of the current directory. If you do provide an argument, make sure it's a directory path.
Commands in Linux have options that can enhance the commands, these options can be written between the command and their argument(s) by writting a space followed by a dash ('-') and the option you want to use.
For example, you can get a detailed version of the
ls command using the
Let's create a new directory, we do this by using the
Mkdir stands for - you guessed it - make directory.
The following command will create a directory called 'test':
If you type
ls now, you will see that a new directory is listed in the output.
You can use the
cd (change directory) command to access the new directory ~
ls will show you that there are no files inside.
~ represents your home directory path, if you want to easily get back to your home, you simply type
We use the
touch command to create empty files.You can create one or more files with this command.
touch file1 file2 will create two files named 'file1' repectively 'file2',
ls will reveal that they were indeed created.
If you want to copy files,
cp will be the command that you need to use.
This command takes two or more arguments, the first one is the file that you want to copy and the last one is either a directory path where you want to place it or the new name for the copied file.
If you specify three or more arguments, the last parameter must be a directory path because it will be the location of the other files (the arguments up to the last one).
cp file1 copy-of-file1 will copy the file1 and paste it in the same directory with the name of
ls to reveal the updated directory structure.
Deleting files is done with the
rm command (remove).
rm command can take one or more arguments.
rm copy-of-file1 command deletes the
copy-of-file1 file from the directory.
Quick mention: When you delete files with the
rm command, the files are deleted for good, you can't recover them, there is no bin or trash can that holds them.
If you want to cut files from one directory and paste them to another one, you will have to use the
mv (move) command.
This command takes two or more arguments, the first ones are the files you want to cut and the last one is the place you want them to be moved to.
The following command will move the file named 'file2' up a directory:
mv file2 .. .
Quick mention: You can switch to the parent directory of your current location by typing
cd .. .
The command to rename files is the same as the one to move them:
The first argument is the file that you want to rename and the second one is the title that you want to give it.
This following code will rename 'file1' to 'file1-renamed':
mv file1 file1-renamed .
You can get details about a certain command by using
This command takes a single argument which needs to be the name of a command.
It will give you a detailed look into what the argument command is doing, how to use it and what are its options.
You can navigate through the manual by pressing the up and down arrows and also the page down and page up keys.
To exit the manual press the
sudo command stands for superuser do, this command allows the current logged user to issue orders that usually would not be permitted because they require a higher administrative priority.
You won't be able to update the packages list by running
apt-get update because this command requires you to have administrative permissions.
You can get around it by prefixing the said command with
Quick mention: Pay extra attention when you use the
sudo command, a beginner can easily damage the operating system by running commands that start with