What is Terminal

Also known as command-line interface or CLI. The terminal is an interface that allows the user to interact with their computer. The terminal provides an interface that we will often be talking about in the previous and following Cloud Computing blog posts. It goes without saying, that most of the cloud computing posts to follow will use the Terminal or an SSH connection – Secure Shell.

Hi Terminal
telnet towel.blinkenlights.nl

The purpose of this post is to assist beginners with a basic guide to get started in using Terminal applications. NOTE: The Terminal images in my samples will look different in colour and font to your computer. That is because I have applied custom themes to my Terminal Application. But, everything will work exactly the same.

Where to find Terminal

The two quickest ways to find Terminal is to press simultaneously on your keyboard:

CTRL + ALT + T

or Click the Super Key and in the search window type: Terminal

Terminal Icon
Find and click the Icon

When to use Terminal

The terminal is powerful and can be used for everything on your computer. That means that you can use it at any time. Terminal often saves time as you can add and remove applications with a simple command. Removing the need to first download an installer program.

Alternative names for Terminal:

  • Console
  • Shell
  • Command Line
  • Command Prompt

Let’s get started

Use the following command to login with Root. This is not something you want to do all the time. By staying logged in as Root you may leave your system open to unsuspected access. The better way to do this is to add the Superuser command to the front of the command you are running.

sudo su

“sudo” means Super User Do. It is better to prefix commands that require root privileges with this and then run the command as superuser/admin/root.

“exit” will log you out when logged in root user.

Another handy keyboard shortcut to know is the “Window + arrow key” This moves the terminal left, right, minimize or maximize the size on the screen.

A command you often use will be to clear the screen once you typed all the way to the bottom of the screen or whenever you feel the need to clean up. The keyboard shortcut is CTRL + L or the terminal command is:

clear

Directory Commands

Terminal opens with a prompt that looks like this: <username>@<machine name>: ~$

Prompt

When you login as a superuser you will be taken to your home directory. Every user has their own home folder named with their username.

Directories and files

If you are a Windows user some of the namings in Linux may be different, but they basically mean the same thing. Directories are what in Windows refers to as folders and files are often referred to as documents. That means that files are located in directories/folders.

Present Working Directory: The first command you can use is to determine where you are or “Present Working Directory”.

pwd

What is in the directory? to see the contents of a directory you use the list command. Variations of the list command exist, depending on how you want to display the information.

Normal List Directory

ls

List Directory with Details

ls -l #Detailed view of directories
ls -la #Long listing including hidden files

ls command
List Commands

In most cases, Hidden files are created by the system and are files that you should not have to be bothered by. Hidden files start with a “.” and as the name suggests will not show up during normal listing operations.

To change directories is made simple with the “cd” change directory command. One thing to take note of is that Linux is Case Sensitive. That means you need to type the capitals and lower case characters as they are to make use of the commands.

By adding a space and double dot ” ..” to the cd command you move to the previous/parent directory also known as UP one directory. To jump directly to your Home Directory you postfix the cd command with a space and tilde symbol ” ~”.

cd .. #Move one directory up.

cd ~ #Go to the home directory.

cd <dirname> #Moves into the named directory.

Change Dir

Manipulate Directory Commands

Creating and removing directories is quick and easy with the make directory and remove directory commands. Do note that removing directories containing files requires a recursive switch that is stated as ” -R”. Furthermore, you need to be aware that removed directories will not be prompted for removal as in Windows, as soon as you execute the command the directory is removed. Spaces in filenames will create separate directories.

Renaming directories uses the same command as renaming files and will be explained in the following section.

mkdir <add file name> #Create a directory
rmdir <add file name> #Remove empty dir only
rmdir -R <add file name> #Recursive – deletes contents & directory

Create Directory

File Commands

Creating files are done with the “touch” command followed by a space and the filename and extension. The touch command creates an empty file, and when run with no extension specified will create a .txt extension by default.

touch <filename>.<extension>

Two ways to create files

Files can easily be created directly as explained next or by using the terminal’s internal editor. We will deal with the editor a little bit later.

It is possible to create files that are not empty. The cat command is followed by the bigger than sign and the file name creates the file and then waits for text input. Type the text input string and then enter. Once you are done adding the data, simply click Ctrl + z on the keyboard to save the file.

Using only the cat command with a space and the filename outputs the file contents to the screen. For long files, you can add the “less” switch, like this: “cat less <filename>”. This will break the long text up into readable chunks.

cat > <filename>
Hello World
ctrl + z to save and exit

cat >> <filename> #add data to file

Make a text file

Copy and move files

Now that we know how to create files we can learn to move them around and create copies. This is done with the copy command “cp” followed by a space, then the old file name and another space and the new file name.

It is possible to create copies directly into a directory. To do this you need to apply the sudo switch.

cp <old filename> <new filename> #Copy to a new filename
sudo cp <filename> /<dirname> #Makes a copy into a directory

Copy and move file

The “mv” command is used to move files and directories into different directories. If you follow the samples as given and you jump back into the /sample folder, you will notice the “newname.txt” file we copied into the Dir1 directory is still there. So the next step will be to remove the file. For that, we employ the rm command with the filename.

rm <filename> #removes a file

mv <source> <target> #Moves file into another directory
mv #Rename a file

Move Dir and File

Nano Editor

Nano is an editor used in Terminal to edit files. The editor supports basic functions like: text highlighting and formatting, copy, paste, spellcheck etc. Nano comes in handy when you need to change settings in configuration files and more.

Starting nano is simple, in the terminal you prefix the file that you want to edit with nano and it opens. You can find the official site for nano editor here

nano <filename> #opens a file for editing
The commands to the bottom of the screen work with ctrl + <shortcut>

Nano Editor

File Permissions

Files come with Permissions, you may have noticed them while listing directory contents in previous steps. File permissions can be set for Files or Directories in Terminal, they look like this: drwxr-xr-x.

Permissions Details

  • drwxr -> Owner can delete,read,write,execute
  • xr -> Group permission
  • x -> Public permission
Permissions

System Commands

which <search string> #Search for a file or directory

history #Shows last 500 commands used

ifconfig Your network information

iwconfig Your wireless network information

ping <ip/domain> #This pings a server and waits for pong/reply – handy to see if a machine is up and running
ctrl + C #stop ping

uname -a #Get a summary of your system

blkid #Get current hard drive/partition information

top #Get information about processes
Press q to quit

lsusb #Get all usb information

df #Get detailed storage space information

lspci #Get all info related to pci

Package Managers

In Linux, Package Managers are the software applications that help users to easily install, remove, update, search and download software applications. Package managers are accessible via Terminal and command or in a graphical interface(GUI). Ubuntu uses the apt-get type, and therefore the commands in Terminal will look as follows:

sudo apt-get install <packagename> #Install a package

sudo apt-get remove <packagename> #Removes a package

sudo apt-get update #Updates your entire system

Combining commands is possible as shown here:
sudo apt-get update && sudo apt-get upgrade

Closure

These are basic commands to run local, if you want to go further to connect to a web server etc. you use SSH console. It is a secure connection, unlike FTP, that does not offer encryption.

I hope these commands help, feel free to bookmark this post and come back to it as you need a cheat sheet. Remember that you can ask questions and leave comments below.

Meet the Author


Renier is a Full Stack PHP Developer who helps businesses with digital transformation. Before starting Quickfood, Renier worked as a technician and a business owner in the hospitality industry and website developer. After a successful career helping various retail stores, leasing agents and more with their websites, Renier now dedicates his time to Cloud-Based Business Applications. Learn how Renier got his start as a Cloud Application Developer.

Leave a Reply

Your email address will not be published.