Linux For Dummies: Ubuntu Terminal

Basic commands for the file system management

I introduced in the previous article, available here, the basic concepts concerning the Linux world. Today we are going to have a look to some basic operations that we can perform using the terminal in an Ubuntu-like operating system.

What is the command line?

Shell, terminal and command line are words that commonly stand for a text interface device. It can be used to perform the majority of the tasks like moving across the file system and manage it, download, install and uninstall programs and also to configure the hardware, create scripts and many other stuffs.

Basically it is an alternative way to the common graphical interface to manage the machine. In fact, we can perform exactly all the operations we carry out through the graphical interface using the command line.

Usually, a classical Ubuntu terminal appear like the one above.


Let's have a look to some operations that we can perform via the terminal.

How do I start the terminal? 

Abbiamo due modi per utilizzare il terminale: avviare la macchina in modalità terminale oppure avviare la shell da interfaccia grafica.

There are two ways to use the terminal: starting the computer in textual interface mode or starting the shell from the graphical interface.

In order to start the terminal via the graphical interface you have to:

  • Ubuntu 18.04 and following: select the application menu and type terminal;
  • Previous releases: select the Ubuntu button and type terminal;

Commands manual and syntax

When we have to type commands, it may happen that you don't remember the syntax or the function of some options that you can write next to the command. In that case two commands help us:  man  and  help .


The  help  command is the one that reminds us the syntax of the command that we are using. Let's have a look to how we use it.

ls --help  is the guide that explains the syntax of the   ls  command;

ls --help | less : it allows us to visualize the guide of the  ls  command on more pages;


The command  man  shows us the manual pages of the command that we want to use, if it exists.

We just have to write:

man <command>  where with <command> we mean the command whose manual page we want to consult.

Move across the file system

We must first of all understand how the file system is structured in the Ubuntu environment. In this environment the file system is represented as a tree, whose root is everyone's parent node.


By the command line we can also move far and wide across the file system. The command that we need is  cd. Let's look how it works.

  • cd Desktop  if the current directory is home it takes us to the Desktop folder. Generally we can replace Desktop with the name of any directory as long as it is a sub-directory of the one we are. In alternatively we are forced to use an absolute path to reach the folder;
  • cd ..  ite allows us to move from the current directory to the parent directory;
  • cd /directory  from whatever folder we are it allows us to move to the directory folder;
  • cd ~  or  cd  leads to the home directory of the user;
  • cd -  leads to the previous directory;

Show the current directory

pwd  shows the current directory we are in.

Show the content of a directory

The moment we want to consult the contents of a folder, the ls command comes to our rescue. Let's see some examples of use.

  • ls -l  show the detailed directory's content;
  • ls -la  show the detailed directory's content including the hidden files;
  • ls -S  show the file list sorted by size;
  • ls -X  show the file list sorted by extension;

Copy files and directories

In this case the right command is  cp . Let's see how we use it.

  • cp file1 cart1  copies the file called file1 into the directory called cart1. We can also use the paths, absolute or relative, of both the elements;
  • cp -r cart1 cart2  copies every element inside cart1 into cart2;
  • sudo cp -a cart1 cart2  copies all the elements inside cart1 into cart2 mantaining the same permissions and information on creation date and time;

Move or rename files and directories

The command that we use is  mv .

  • mv old new  renames the file old into new;
  • mv file1 cart1  moves the file file1 into the directory cart1;

Delete files and directories, create directories

The command that we use is  rm .

Let's see how we use it.

  • rm file1 file2 ...  removes the files in the list (file1, file2, ...);
  • rm *.*  deletes everything from the directory. Be careful when you use it! The command can be modified writing  rm *.extension  deleting all the files with extension .extension;
  • rm -rf cart1  deletes all the content of the directory cart1;

In case we want to remove a folder, as long as it is empty, we will use the command  rmdir nameOfTheDirectory .

If we want to create a new directory, we will use the command mkdir new_dir, so creating a new empty directory called new_dir.

Show the content of a file

The command that allows us to see the content of one or more files is the command cat. Let's have a look to some examples. It is good practice to explicitly write the file extension, in order to avoid ambiguity between any files with the same name but different extension (for examples .java files and .class files).

  • cat file  shows the content of the file called file;
  • cat file1 file2 > file3  creates the file file3 with the content of file1 and file2;
  • cat file1 file2 >> file3  adds to file3 the content of file1 and file2;
  • tac file  shows the content of the file but in reverse order;

If we need to cisualize the content of a file on more pages we will not use cat but we will use more. The Enter key advances the view line by line while the space bar advances page by page.

  • if we want to show the file content on more pages we will write  more file where file stands for the name or the path of the file to show;
  • if we want to visualize the content of a directory on more pages we will write  ls -l | more ;

If instead we want to display the contents of files or directories always on multiple video pages but with the possibility of scrolling back and forth we will use the less command. To stop use CTRL + Z.

  • less myFile  shows the content of the file called myFile on more pages;
  • ls -l | less  shows the detailed content of a directory on more pages; 

We have given a very general overview of basic Ubuntu commands. Further on, addressing other aspects of the penguin world, we will introduce new commands. For now, experience people, experience!wink

Alessio Mungelli

Alessio Mungelli

Computer Science student at UniTo (University of Turin), Network specializtion, blogger and writer. I am a kind of expert in Java desktop developement with interests in AI and web developement. Unix lover (but not Windows hater). I am interested in Linux scripting. I am very inquisitive and I love learning new stuffs.


Related Posts

    JavaScript: Promises explained with simple real life examples

    Handling asynchronous data flows is complex, who hasn't faced codes like this one?: checkWeather('palma de mallorca', (error, weather) => { if (error) throw error; if (weather === 'well') { return checkFlights('palma…

    Web shells as a security thread for web applications

    Over the past two decades, web applications as an alternative to traditional desktop application have been on to rise. As their name suggests, they are installed on web servers and accessed…

    Linux For Dummies: Permissions

    In the previous articles I made a short introduction to the Unix world and in the following article I have dealt with the basic commands for the file system management. Today we are…

    Facebook: how to remove hidden data and personal information

    Facebook is a great social network that allows us to be always updated on all the news of our friends or family or even the most relevant news of the…

    Linux for Dummies: Introduction

    If you have thought about migrating from Windows to a Unix operating system, or Linux specifically there are things you should know. The goal is to give essential information (and…

    How to Stay Safe When Shopping Online

    It can seem that not a day goes by when we don’t hear of some new hacking case or people who have had their sensitive date compromised via the internet.…

    Java Design Pattern: Builder Pattern

    Today we are going to talk about a creational pattern that in many situations can represent a useful alternative to the construction of the objects using the constructors: the Builder…

    Java Design Pattern: Strategy Pattern

    One of the most popular patterns is the Strategy Pattern. It is also one of the easiest patterns. It is a member of the behavioral patterns family, it has the duty…

    Java Sorting Algorithm: Selection Sort

    Today we are going to analyze a sorting algorithm that is not very efficient but often used in various fields. We are talking abou the Selection Sort. Let's have a look. Intuition The…

    What Are The Best Methods to Make Money Online

    More and more individuals are moving from a regular job they have to work on the internet. This trend continues to grow at quite a rapid speed, and since we…

    Java Sorting Algorithm: Bubble Sort

    Programming, the need to order the collections of data or objects that must then be manipulated often arises. Ordering a list can be useful in cases where you have to do…

    Java Sorting Algorithms: Merge Sort

    Today we are going to analyze one of the most used sorting algorithms: the Merge Sort. It is part of the Divide and Conquer family, just like the  Quick Sort. Merge Sort offers a better performance…