DEV Community

Cover image for An introduction to Linux (Ubuntu) basic commands.
Bernard Chika Uwaezuoke
Bernard Chika Uwaezuoke

Posted on

An introduction to Linux (Ubuntu) basic commands.

This article is made to serve as an elementary introduction to Linux Operating System. It is designed to help a beginner understand the structure and working of Linux as an Operating System using Command Line Interface (CLI).

The first challenge that most individuals aspiring to become Enterprise Server Administrators, Cloud Developers, DevOps Engineers and other related fields encounter is the fact that most servers are running on Linux Operating Systems as against the more popular Windows Operating System mostly used in personal computers.

Therefore, it becomes imperative for such an individual to have an understanding of how Linux works, its basic commands, packages and structure. This is what this writeup set out to achieve.


Linux is an open-source operating system (OS). It was originally conceived of and created as a hobby by Linus Torvalds in 1991. Linus, while at university, sought to create an alternative, free, open-source version of the MINIX operating system, which was itself based on the principles and design of Unix.

One of the key features of Linux is its open-source nature, which means that its source code is freely available for anyone to view, modify, and distribute.

Linux provides a powerful and stable platform for running software and applications. It is known for its robust security features, customizability, and scalability. The operating system supports a wide range of programming languages and frameworks, making it a favored choice among developers.

Linux Distribution
A Linux distribution, often shortened to Linux distro, is an operating system compiled from components developed by various open-source projects and programmers. Each distribution
includes the Linux kernel (the foundation of the operating system), the GNU shell utilities (the terminal interface and commands), the X-server (for a graphical desktop), the desktop environment, a package management system, an installer and other services.

Some popular Linux distros:
Red Hat Enterprise Linux & CentOS, Fedora, Debian, Ubuntu, OpenSUSE, Linux Mint and others. Recall that Linux is open-sourced, so we have many distributions that have been developed overtime, though they all have the same underlying structure and concept.

For this very article, we will be using the Ubuntu Linux distribution.

Let us take a look at some basic Linux commands and concepts.

Shell prompt:

Image description
This is called the SHELL prompt. username@machinenamefollowed by the current working directory and a $ sign. This is the first thing that displays when you open your terminal. The $ sign implies the shell is ready for input.

Moving around the command line:

If we press the up-arrow key, we will see the previous command.
Press the down-arrow key and the previous command disappears.
We can position the cursor anywhere on the command line by using the left and right-arrow
keys. This makes editing commands easy.
If you highlight some text by holding down the left mouse button and dragging the mouse over it, it will COPY the text. Pressing the right mouse button will cause the text to be PASTED at the
cursor location.


Here we look at how to navigate the file system on our Linux system. Linux organizes its files in what is called a hierarchical directory structure. This means that they are organized in a tree-like pattern of directories (sometimes called folders in other systems), which may contain files and
other directories. The first directory in the file system is called the root directory. The root directory contains files and subdirectories, which contain more files and subdirectories and so on.

General Commands

The current working directory pwd

Image description
To see where you are, you can use the pwd command, this command means “print working directory” and it just shows you which directory you are in, notice that the path stems from the root directory.

/ means root directory
To switch to root user, we use the command sudo su (super do switch user).

Image description
Type exit and hit the enter button to switch from root user.

~ means current user’s home directory

Image description

apt package manager of Ubuntu used for installation of applications and updates. Example, apt install nginx to install nginx in ubuntu Linux.

Listing the content of a directory
These commands are used to view the content of a directory you are working on.

ls short list of the content only
ls -l detail list of the content

Image description

ls -a list content with hidden folders
Image description

ls -la list content with details, permissions and hidden folders.

Image description

Changing Working Directory cd

cd User Home directory (cd takes you from anywhere to the current user’s home directory)

Image description

cd / Root directory
Takes you to the Root directory from your current directory.

Image description

cd . Move back to current/present directory that you are working in.

cd .. Move back to current directory's parent directory

Image description

Directories (Folder) & File
mkdir: to make a directory (folder) mkdir foldername
Image description
We created the directory and used the ls command to view it.

rmdir: To delete an empty directory we use this command rmdir foldername

Image description

touch: We use this to create new empty files touch

Image description
We used the command to create a file named file2, and viewed it with the ls command.
Touch is also used to change timestamps on existing files and directories.

rm: to remove a file we use this command this way rm filename. Let us use it to delete file2 that we just created.

Image description
We used the command to remove the file and used the ls command to show that the file is no longer available.

echo: This command is used to print or write into a file. Example, echo “Welcome to Linux” > filename This will write "Welcome to Linux" to the file with the designated name.

Image description
We just used the command to write "Welcome to Linux" in a the file ben and viewed the content of the file with the cat command.
If a file name does not exist, echo can create the file and write the content into it.

cat: short for concatenate used to display a file content. cat filename as used above.

Linux File Editors

We use these commands to edit files..

To use the vi command, type vi filename to edit an existing file or create a new file with the designated file name and write a content in it.

Image description

This will take us into the file to edit it.
Press I to insert the content.
Image description

After editing Press ESC to exit insert mode.
Then use “:wq!” to save and exit editor or “:q!” to exit editor without saving.

The nano command functions in similar way to the vi command.

Let us use the vim command to create a text file and save it in a directory (folder) named "myfutureself"

  • Create the directory "myfutureself" with mkdir command.

Image description

  • Use command cd myfutureself to get into the file we created.

Image description
We are now inside the new directory (myfutureself). Let us go ahead and create the file.

  • Use the vim command to create a file named congratulation.

Image description
This brings us inside the file congratulations
Image description
Press I to insert the content (Write in the file).

The file content
This file is a congratulatory letter to my future self.
Image description

Image description

Image description

  • After editing Press ESC key to exit insert mode. Then use “:wq!” to save and exit editor, by hitting the enter key.

Image description

Back to shell prompt.
Image description

  • View the file with the ls command, and the file content with the cat command.

Image description

File Content viewed with cat command.

Image description

Hope this guide helped you get started with understanding the Linux Operating System.

Thanks for your time, please subscribe and like my page.

Top comments (0)