The Linux commands cheat sheet is written for people who are new to Linux. If you are unfamiliar with Linux, this crash course will help you to get started with it. We’ll use Ubuntu as our base distribution here.
Ubuntu is one of the most customizable Linux distributions available today. Almost every Linux enthusiast begins their journey with Ubuntu, as it is one of the most popular Linux distributions for newcomers.
Ubuntu command syntax
The basic syntax of a command is simple. It can accept parameters or arguments.
Here is how you can specify parameters or arguments in the Ubuntu command.
A command accepts one parameter or argument.
A command accepts multiple parameters or arguments. Arguments can be separated by space.
command argument1 argument2 artument3
If a command accepts no arguments then the syntax will be very simple. For example, if we want to print the list of folders and files in the current directory then the command will be as follow:
List of basic Ubuntu commands
sudo (work as a super admin)
The sudo means “SuperUser DO”. This command is similar to “Run as administrator” in Windows operating system. It allows you to run programs or other commands with administrative privileges.
sudo gives a user temporary administrative rights.
Use sudo before a restricted command to make it work. The general syntax looks like this.
For example, we will update the package database in Ubuntu.
sudo apt-get update
apt-get and apt (package managers)
apt stands for “advance package tool“. It is a package manager for Ubuntu. The apt-get command is also similar to apt. They both do similar tasks most of the time.
apt is newer then apt-get.
One of the most important Ubuntu commands that any starter should know is apt-get or simply apt. Any package can be installed, modified, upgraded, or removed using it.
sudo apt-get update
sudo apt update
Working with folders and files
To create a new folder you can use the following command.
The mkdir means ‘make directory’.
You can create multiple folders with this command
mkdir folder1 folder2
Create files with ‘touch‘ command. It accepts one or more argunments.
sudo touch file.txt
Creating multiple files.
sudo touch file1.txt file2.txt
Deleting folders and files
The deleting of files is simple. Use rm command.
Remove multiple files.
rm file1 file2
However removing folders is not simple as files. You need to use -r option with it.
When rm is used with the -r or -R options, it deletes all matching folders, subfolders, and files in a recursive manner.
rm -r folderName
If the specified directory is empty, the -d or —dir option can be used to remove it instead.
rm --dir folderName
It is possible to specify a relative or absolute path of a folder or file. The rm command can accept the path as an argument.
For example, we want to delete the file “index.html“. We are specifying the absolute path to the file. Absolute paths usually start from the root.
sudo rm /var/www/index.html
Rename files and folders
Rename files with the mv command. For example, renaming ‘file1.txt’ to ‘file2.txt’ in the terminal will look like this.
sudo mv file1.txt file2.txt
similarly to rename folders use the same syntax as mentioned above. This command will rename folder1 to folder2.
sudo mv folder1 folder2
Copy folders and files
The cp command is used to copy files and folders in Ubuntu.
Copy file from one folder to another.
For example, copy file.txt to folder2 in same directory.
sudo cp file.txt ./folder2
Specify path if necessary. Both the absolute and relative paths are valid.
For example, copy a file available in a path (/folder1/file.txt) to another path (/folder2).
sudo cp /folder1/file.txt /folder2
How to copy files one step up in a folder?
Consider a folder named ‘folder2‘ located inside ‘folder1‘ and it contains a file called ‘file.txt‘.
The following command will copy file.txt to folder1.
sudo cp file.txt ../folder1
Copying the folder is little bit different then files. You need to use -r with the copy command.
The following command will copy folder1 to folder2 (folder2 >> folder1).
cp -r folder1 folder2
Software Installation in Ubuntu
How to install programs in Ubuntu?
You can install packages in many ways. Here is a list of the most commonly used approaches, with links to more specific explanations for each.
1: Using web browser
The APT protocol or apturl is a quick and easy way to install software from a web browser.
2: Using GUI based methods
The Ubuntu Software Center is a simple built-in store to install different programs and add-ons on your Linux Operating system.
There is another GUI-based software for apt called Synaptic. Synaptic is used to update, remove or upgrade any package in your system.
3: Using Terminal (via command line)
Note: We focus on some simple steps for starters. There is a list of all the methods to install and remove packages. Learn more here.
File navigation commands
The GUI-based Operating systems made it easy to click and open a folder. It is simple for a normal user. However, in this Linux commands cheat sheet you will get all the commands which are mainly used by normal people as well.
Developers should be familar with commands that makes work flow faster.
The first and most important command is ‘cd’. It means change directory. You can jump from one directory/folder to another using this command.
Goto home directory from any location. (cd tilde sign)
or simply type cd and press enter.
The home looks like this in the terminal.
username@dell:~$ OR root@dell:~#
Goto root directory
The root directory will be a simple slash. The command to print the current working directory is pwd. pwd stands ‘print working directory.
root@dell:~# pwd /root OR username@dell:~$ cd / username@dell:/$ pwd /
Any directory may or may not contain subfolders or directories and files. to view, all the files and folders using the following command in Ubuntu.
‘ls’ is used to view the list. The default list printed by this command will look random, floating from left to right.
niat@dell:/$ ls bin dev initrd.img lib64 mnt root snap sys var boot etc opt run srv tmp vmlinuz cdrom home lib ....
You can print each file and folder name in a new line. use “ls -1” command.
niat@dell:/$ ls -1 bin boot cdrom dev etc home lib lib64 lost+found media mnt ....
If you want to print the details with the files then use “ll” or “ls -l” command.
niat@dell:/$ ll total 2097264 drwxr-xr-x 24 root root 4096 Apr 14 17:05 ./ drwxr-xr-x 24 root root 4096 Apr 14 17:05 ../ drwxr-xr-x 2 root root 4096 Apr 14 17:00 bin/ drwxr-xr-x 4 root root 4096 Apr 14 17:07 boot/ drwxrwxr-x 2 root root 4096 Apr 14 19:48 cdrom/ drwxr-xr-x 20 root root 4500 Apr 17 14:54 dev/ drwxr-xr-x 129 root root 12288 Apr 15 20:44 etc/ drwxr-xr-x 3 root root 4096 Apr 14 19:48 home/ .....
So far we shared some fundamental commands in this Linux commands cheat sheet. furthermore, we will discuss some intermediate-level commands.
The package managers in Ubuntu
By default, you will get “apt” or “apt-get” package managers. We will focus on the usage of these package managers here.
How to update the package list in ubuntu?
The package manager apt is used to update, remove, install and upgrade the packages in the database.
Print all the available packages in the database. This command will display a huge list of packages.
Update this list and add new or updated packages. This command will update the package database.
Install new package in your system. use the ‘apt install’.
apt install packageName
for example, we will install nano.
apt install nano
Remove any package by its name using apt.
apt remove packageName
Remove the above installed package (nano).
apt remove nano
Some tips in our Linux commands cheat sheet.
There are some tips and tricks or you can say some useful commands that may help you while working on your project.
echo command print some text on the terminal.
echo 'this is a text' this is a text
There is a very useful command that displays all of the last commands used recently. The command is simply called ‘history‘. The ‘history‘ command, by default, will show the last 500 commands you’ve typed.
The output will be something looks like this.
username@dell:~$ history 1 sudo apt install apt-transport-https curl 2 apt update 3 sudo apt update 4 sudo apt install apt-transport-https curl 5 clear 6 sudo apt install brave-browser 7 sudo apt install apt-transport-https curl ....................
The whoami command is used in both Unix and Windows operating systems.
It’s essentially whoami, which is the concatenation of the strings “who,” “am,” and “i.”
It shows the current user’s username.
niat@dell:~$ whoami niat
Conclusion on Linux commands cheat sheet
This guide does not attempt to cover all commands available in Ubuntu. It focuses on the small core commands that you’ll use most of the time and aims to make them more complicated commands easier to use.
Download Linux commands cheat sheet
The following command covers all the basic Ubuntu commands. You may find it very useful.