To use Linux in an effective manner, you can use a terminal(command line) that gives you control over the operating system services. To use a command line for more control and quicker execution of tasks, you must know the basic commands. In this hands-on lab, we are going to learn the top basic Linux commands that help you to understand and use Linux systems in an effective manner. So let's get started

What is a Linux command?
Linux command is a program or utility that runs on the command line. The command line is an interface that takes text from the user's keyboard and processes them into instructions for your system. The Linux command line is case-sensitive.
Linux commands are basically used to perform multiple tasks, like handling different processes, monitoring the whole system, installing packages, file manipulating, handling system services, etc.
Syntax:
command [option(s)] <arguments>
command - is a small executable program located on a Linux disk (generally at /usr/local/bin
location)
option(s) - works as a switch, used to pass the parameter to a program(command). It modifies or changes the execution of the command.
argument(s) - provides the required information for a command to execute.
Linux commands
The Linux system has a number of commands. In this hands-on lab, we will learn the top primary and most useful commands, which will help us understand the Linux system and complete some basic tasks.
Linux Commands Cheat Sheet
For quick reference, review the below table for basic Linux commands.
Index | Command | Usage |
1 | man | This command provides a user manual for commands. |
2 | ls | This command lists the content of a directory. |
3 | cd | This command is used to change directory. |
4 | cp | This command is used to copy files and directories. |
5 | mv | This command is used to move or rename the files and directories. |
6 | cat | This command is used to show file content. |
7 | touch | This command is used to create a new empty file. |
8 | mkdir | This command is used to create directories. |
9 | rm | This command is used to delete(remove) file or directory (directory recursively can be deleted ) |
10 | pwd | This command is used to print the working directory. |
11 | find | This command is used search the file in directories. |
12 | apt or apt-get | This command is used to install/update/delete the package as it is a package manager tool. |
13 | grep | This command is used to search and print the lines on a terminal that match the pattern. |
14 | less | This command is used to read/inspect files interactively (page wise) |
15 | head | Display first lines of a file (by default shows 10 lines) |
16 | tail | Display last lines of a file (by default shows 10 lines) |
17 | echo | Display text/string on terminal |
18 | ps | This command is used to print processes status from the linux system. |
19 | top | This command is used to print processes status and detailed information in real-time (dynamic ) |
20 | sudo | This command is used to execute the command as a super user by giving root user privileges. |
21 | useradd | This command is used to add new users to the system. |
22 | passwd | This command is used to set passwords for users. |
23 | userdel | This command is used to delete user. |
24 | history | This command is used to show the list of previously executed commands |
Now, let's dive deep into all the commands mentioned in the cheat sheet above one by one.
man command
man [OPTION]... [COMMAND NAME]...
This is one of the most useful commands in the Linux system. There are multiple commands(packages) with different functionalities and as a user/programmer who wants to get a user manual for that specific command. The man command provides detailed information about that specific command.
man mkdir
unminimize
command and then again execute the man
command.To exit the manual page press q
.You can use the man --help
command for more information about options.
ls Command
ls [options] [file...|directory..]
The ls
command is used to display all the content (files and directories) from the current and other directories.
ls
And if you want to see all content along with hidden directories and files, you can use the -a
option.
ls -a /etc
The -f
option is used to list the files without sorting.
ls -f *.conf /etc
Few other important options for ls
command
-l
- option used for long listing format
-t
- to sort files depends on modification time, priority is for newest file
-r
- reverse the order
ls -ltr /etc
The hidden file and folder are shown as dot (.)
. For more information about options, you can use the ls --help command.
cd command
cd <directory path>
While using the terminal due to different tasks it's important to move through the different directories. The cd
command (change directory) is used to change the current working directory.
cd /etc/
For more information about options, you can use the cd --help
command.
cp command
cp [option(s)] <source path> <destination path>
cp
(copy) command stands for copying files and directories from the source path to the destination path. with the help of the cp command.
cp /etc/os-release /tmp/
ls /tmp/
You can also copy the whole directory in a recursive manner by using the “-r
” option.
cp -r /tmp ~/temp
ls ~/temp
For more information about options, you can use thecp --help
command.
mv command
mv [option(s)] <source path> <destination path>
mv
(move) command is similar to the cp command, the difference between these two commands is the mv command is used to do cut-paste
(move) or to rename
the files or directories from your system.
For example: to move(cut-paste) one directory into another directory
mv /tmp/os-release /tmp/os-info
ls /tmp/
To rename any folder or file we can use the mv command
mv ~/temp ~/temp_data
ls ~/temp_data
For more information about options, you can use themv --help
command.
cat command
cat [option(s)] <filename>
When you want the content of the file on the terminal, or if you want to write file content, or combine the output of files into another file we can use the cat(concatenate
) command.
For example to display file content
cat /etc/os-release
In the below example, by using the “cat” command we are going to merge 2 files(filename1 and filename2) and store the output in 3rd file(filename3).
cat test1.txt test2.txt > test3.txt
cat test3.txt
the cat command can be used to create a new file and insert data into that file with the help of the >
greater than sign. The file can be saved with the help of the ctrl+d
keys. By using >
the content of the existing file will be overwritten.
cat > test4.txt
hello this is file number 4
The cat<< EOF > file_name command can be used to create a new file, and also displays an end marker at the end of the file which saves the content till the given end marker. The file can be saved with the help of the ctrl+d or EOF word at end of the file.
cat << EOF > test5.txt
This is ubuntu
To see user info see /etc/passwd
EOF
For more information about options, you can use the cat --help
command.
touch command
touch [option(s)]<file name>
To create a new empty file touch
command is used.
touch file1.txt
ls
To modify the timestamp of the file touch command is used with the -m
option.
For more information about options, you can use the touch --help
command.
mkdir command
mkdir [option(s)]<directory name>
To create a new directory(s) mkdir(make directory
) command is used. The user must have the privilege to create a new directory.
for example to create a new directory.
mkdir linux
ls -l
-p
or --parents
command is used to create subdirectories.
mkdir -p ~/app/frontend
ls -l ~/app
Also to create a directory with full permissions(read, write, execute) you can use the -m
(mode) option.
mkdir -m 777 fullpermission
ls -l
For more information about options, you can use the mkdir --help
command.
rm command
rm [option(s)] <file/directory name>
The rm
(remove) command is used to delete files or directories.
rm /tmp/os-info
ls -l /tmp/
you can use the -r
(recursive) option to delete an empty directory.
To delete a directory with content inside of it, you can use (force) -f
and (recursive) -r
options.
rm -rf ~/temp_data
For more information about options, you can use the rm --help
command.
pwd command
pwd <options>
To get the absolute path of the current working directory on the terminal the pwd(present working directory) is used.
pwd
For more information about options, you can use the pwd --help
command.
find command
find [option(s)] [path] <expression>
To search files in the directory find
command is used. The find command takes the regex expression With the -name option.
find /etc -name opt
For more information about options, you can use the find --help
command.
apt or apt-get command
apt install <package name>
To install, update, and remove any software(pkg) from the system the apt
command is used. It is a package management tool that helps to manage software(pkg) and its dependencies as well.
apt update && apt install mysql-server -y
Some of the most commonly used options are update
, upgrade
, etc.
Update- it synchronizes package files from their source files.
Upgrade- it installs the latest dependencies of installed packages.For example-
For more information about options, you can use the apt --help
command.
grep command
grep [option(S)] <search string> <file name>
To search specific string from a file grep(global regular expression print) command is used. This is one of the most common command. It prints all lines that match the regular expression.
cat /etc/os-release | grep VERSION
For more information about options, you can use the grep --help
command.
less command
less [option(s)] <file_name>
less command helps you to read large files page-wise. less command helps you to inspect files backward and forward manner. The less command doesn't load the entire file, it loads in parts which makes it easy to read the large file. To come out from this terminal press q
less /boot/grub/grub.cfg
or
you can also use this
cat /boot/grub/grub.cfg | less
For more information about options, you can use the less --help
command.
head command
head [option(s)] <file_name>
The head command is used to display the first line's content from a file. by default, it shows the first 10 lines of the file. It prints N number of data of given input. It also considers blank lines not only text lines.
For example to see the first 10 lines from the file.
cat -n /boot/grub/grub.cfg | head
For more information about options, you can use the head --help
command.
tail command
tail [option(s)] <file_name>
The tail command is opposite to the head command it is used to display the last line's content from a file. by default, it shows the last 10 lines of the file. It prints N number of data of given input. It also considers blank lines not only text lines. The tail command is useful for reading the error message.
For example to see the first 10 lines from the file.
cat -n /boot/grub/grub.cfg | tail
For more information about options, you can use the tail --help
command.
echo command
echo [option(s)]<string>
The echo command is used to display text/string which is passed as an argument on the terminal. This command is mostly used in shell script and batch files to give output on screen or to insert data into a file.
echo "This is ubuntu"
echo *
command will print all present files/directories, it's similar to the ls command.
echo *
echo /etc/*
command is similar to cd /etc && echo *
Also, to create a new file and redirect the echo command output to the file by using >
OR >>
rather than printing it on the screen. When you use the >
operator, the file will be overwritten. If the file does not exist, it will be created by using the >
OR >>
operator
echo "This is file1" > file1.txt
cat file1.txt
when you use the >>
operator, the data get appended to the file.
echo "file1 is modified" >> file1.txt
cat file1.txt
For more information about options, you can use the echo --help
command.
ps command
ps [options(s)]<optional paramter>
To list out the currently running process in the shell ps
command is used. It gives a snapshot and useful information on the running process. It gives information like PID(process ID), TTY(type of the terminal), TIME(running time), CMD(executed command), etc.
ps
There are multiple options for example if you want to see all running processes.
ps -A
If you want to display all process(a) with user name(u), which are executing(x), you can use the ps
command.
ps aux
For more information about options, you can use the ps --help
command.
top command
top <option(s)>
The top
(table of processes) command is used to monitor the CPU performance. The top command is similar to the ps
command, but the difference between these two commands is, the top command displays real-time data
. the top command gives detailed information. The first top section of the top command displays statistics of the overall running process and usage of the system, and the second part contains a list of currently running processes.
top
Top command provides information such as
- PID- process ID which is unique for each process
- USER- user name of (owner) process
- PR- Process Priority, As lower the number higher in priority(-20 have higher priority-20 have less priority)
- NI- The nice value of task (-ve value have higher priority than +ve value).
- VIRT- The Total virtual memory used by the process.
- RES- Physical RAM used by the process in kilobytes(kb)
- SHR- Shared memory size used by the process in kilobytes (kb)
- S- Process status, It can be anything between {
D
- uninterruptible sleep stateI
- idle stateR
- running stateS
- sleeping stateT
- stopped by a job control signal statet
- stopped by debugger during trace stateZ
- zombie(process are stopped but still exist in the process table) }
- %CPU - CPU usage by a process in percentage.
- %MEM - memory usage of a process in percentage.
- TIME+ - CPU time (time from the start of the process )
- COMMAND - A command which is used to start the process.
For more information about options, you can use the top --help
command.
sudo command
sudo <command>
To assign super user privilege or root user privilege sudo(superuser do) command is used. You have just to add the sudo
command before the others' command. The sudo command is commonly used to install software or edit files, which normal user cant edit.
For example to download package information from all configured sources
sudo apt update
For more information about options, you can use the sudo --help
command.
useradd command
useradd or adduser [option(s)] <username>
To create a new user in the linux system useradd
or adduser
the command is used. These two commands are the same. you can see the new user name in the /etc/passwd
file. Only those users who have root privilege or sudo can add a new user. adduser
also requires a new password for that new user.
useradd ubuntu007
For more information about options, you can use the passwd --help
command.
passwd command
passwd <user name>
To set a new password for the user passwd(password) command is used. you can see the new password for that specific user in the /etc/shadow file in an encrypted format. Superusers have the privilege to change passwords for other users as well.
passwd ubuntu007
For more information about options, you can use the passwd --help
command.
userdel command
userdel [options] LOGIN
To delete a user account and related files to that user userdel
command is used. It deletes entries from the user's list (/etc/passwd
) as well. Superusers have the privilege to delete other users as well.
for example, by using -f
used to forcefully remove the user account even if the user is still logged in. It also deletes the user's home directory and mail spool (/var/spool/mail or /cron).
userdel -f ubuntu007
For more information about options, you can use the userdel --help
command.
history command
history [option(s)]
To see previously executed commands by the user on the terminal history
command is used. This command list up to 500 commands.
history
For more information about options, you can use the history --help
command.
Conclusion
If you want to learn and use Linux effectively, you must know the basic commands. The more you practice and use Linux commands, the better you will do productive work. In this hands-on lab, you learned the most used basic commands to take control of your system’s privileges.
There are lots of more helpful commands. If we have left something out, please let us know and share your favorite Basic Linux commands in the comment section.
In the next hands-on lab, you will learn about Advanced Linux commands to perform Administrator tasks. Have Great learning!