Phone :  +370 (5) 204-1903
Email :  sales@1gbits.com
  1. Dedicated server
  2. Blog
  3. Basic Linux Commands with Examples [Linux Cheat Sheet]

Basic Linux Commands with Examples [Linux Cheat Sheet]

Since the mid on 1990's Linux has been in the market but now has become the most widely used operating system in the world. Nowadays you can find linux into you smartphones, computers, servers, cars, home appliances and pretty much in everything. To make your productive you should have the knowledge on basic linux commands. This blog post will come up with the best commands which you can go for:

Linux Tutorial Nov 13, 20 by Nisal N 18 min Read
Basic Linux Commands with Examples [Linux Cheat Sheet]

Before diving into the Linux cheat sheet or Linux command list too, To know little more about it.

Linux becomes to most popular platforms on the planet. It is mostly used in servers and more than 90% of the internet, today, are powered by Linux servers. It is an open-source and free software which makes it possible for anyone to make changes to the code and redistribute it under a different name. Some of the most famous Linux based operating systems are:

  • Ubuntu
  • Android
  • Fedora
  • FreeBSD
  • Debian
  • Kali Linux
  • CentOS
  • Red Hat Linux
  • openSUSE

Linux is everywhere! This means that the chances of you coming across a Linux interface is very high. A fun fact is that it is a mostly used operating system without a GUI (graphical user interface) and this results in absolute beginners getting lost going about it.

Before we start our journey we need to get familiar with the “terminal” or “shell”.

What is Linux Shell?

In short, the user enters commands to the system, and the system will show the output as a result. Most Linux distributions come with a CLI (Command-line interface), and you use the terminal/shell to input the commands.

Linux distros come with a GUI, but this tutorial is solely dedicated to beginners who want to familiarize themselves with the Linux command line.

Now let’s open the terminal and let’s get started with the commands.

Note that the Linux shell is case sensitive so you should be careful when entering commands.

However, we researched and compiled a list of basic Linux commands that will get you to master the Linux environment. We have separated it according to the level of experience you have:

  1. Basic Linux commands
  2. Intermediate Linux commands
  3. Advanced Linux commands

Basic Linux Commands for Beginners

1. PWD command

Thepwd command will show you the current working directory (also known as a folder) you are working on. It will show the absolute path with all the directories.

An example when you type inpwdcommand and the result will be /root/folder1

pwd command

2. LS command

Thelscommand is used to show all the content inside a directory. The default settings will show the contents of the current directory.

If you want to see the content in other folders, you should type the folder path after the ls command. For example, ls/root/folder1/books to view the files inside the books folder. After the ls command, you should enter the file's absolute path (as seen in the example above).

The ls command has many variations:

ls –R List all files in subdirectories
ls –a List hidden files
ls -al List detailed information of files and directories (permissions, size, owner, etc.)

ls command

3. CD command

Thecdcommand is used to navigate between files and folders. You will need to type the full path or the directory's name (depends on your current directory).

There are some shortcuts to help you navigate quickly:

  • cd .. (with two dots) to move one directory up
  • cd to go straight to the home folder
  • cd- (with a hyphen) to move to your previous directory

An example of cd command will be like cd folder1

cd command

4. MKDIR command

You can use themkdircommand to create new directories. For example, To make a directory called pictures, you can typemkdir pictures.

Here are some tips on using the mkdir command:

  • To generate a new directory inside another directory. Use this formatmkdir pictures/europe
  • Usingpto create directories in between two existing directories. Here's an example:mkdir –p pictures/trips/Europe

mkdir command

5. RMDIR command

If you need to delete a directory, use thermdircommand. However,rmdironly allows you to delete empty directories.

An example:rmdir folder1

rmdir command

6. RM command

You can use therm command to delete files. If you want to delete all the files in a directory then you can use this rm –r command.

Here's an example. Let's say that in folder1 there is a text file namedtest.txt. To remove this file from folder1, enterrm test.txt

7. TOUCH command

Thetouchcommand is used to create empty files directly from the command line. For example,touch docnew.txtwill create a new text file with the name 'docnew'.

You can also create files in a different location by specifying the path:touch /home/1gbits/docs/mywebsite.htmlwhich will generate an HTML file under the docs directory.

touch command

8. FIND command in Linux

Thefindcommand is used to search for files and directories. The findcommand is used to find files within a given directory.

An example is: find docnew.txt

find command

9. MV command

Themvcommand has two functions:

To move a file, you can typemv test.txt /home/1gbits/documentAs shown in the example, you should set the name of the file that needs to be moved and set the path.

To rename files, you can usemv file1.txt file5.txt. The name of the file will be changed to file5.txt.

Here's an example:

mv command

10. NANO command

Thenanocommand is used to create and edit text files. This is an easy-to-use command-line text editor which includes all the basic functionalities of a regular text editor. Let me show you how to create a file using the nano command:

nano test

Enter the text inside the editor and exit to save the file.

11. SUDO command

Thesudocommand will let you perform tasks that require root privileges. However, it is not advised to use this command for daily usage because it will be hard to make it right if an error is made.

12. HISTORY command

Once you start using the Linux working environment daily, you will soon notice that you can run 100s of different commands every day. To know about all the Linux terminal commands that you have entered, you can enter historycommand to review all the commands you've entered before.

13. APT-GET command

You can useaptto work with packages in the Linux command line.Apt-getis used to install packages and requires root privileges. You can use thesudocommand with it. Here are some examples of using the apt-get command.

  • To install the text editor Jed, you can type insudo apt-get install jed
  • To update your current repository, you can type insudo apt-get update
  • To upgrade the system, typesudo apt-get upgrade

14. CAT command

CAT(short for concatenate) is one of the most frequently used commands in Linux. This is used to list the contents of a file on the standard output. For example,cat testdoc.txtwill open the file and display the contents.

Here are other ways to use thecatcommand:

  • cat > filenamecreates a new file
  • cat filename1 filename2>filename3joins two files (1 and 2) and stores the output of them in a new file (3)

to convert a file to upper or lower case use,cat filename | tr a-z A-Z >output.txt

15. CP command in Linux

Thecpcommand is used to copy files between two places through the use of the command line. The command takes two arguments; the first is the file's location that needs to be copied, and the second is the destination of the file where the file should be copied. Here's an example.

There is a file named my.txt in the current directory. You want to move this file to a folder called personal. Type this commandcp my.txt /home/user/personal/

Note the spaces used in the command.

16. ZIP, UNZIP command

Use thezipcommand to compress files into a zip archive and use the command to extract the zipped files from a zip archive.

17. MAN command

There are many Linux commands, and, naturally, we don't remember what each of them does. In such situations, themancommand comes to help. It shows the manual pages of the command. For example, man lsshows the manual pages of the ls command.

No matter command, with themancommand, you can know everything about each of them.

man command

18. WHATIS command

Whatiscommand in Linux is used to get a one-line manual page description. In Linux, each manual page has some description within it. So this command search for the manual pages' names and show the manual page description of the specified filename or argument.

Here's an example: whatis -help which will display a help message with one-line explanations.

Intermediate Linux Commands

1. ECHO command

Theechocommand is used to move data into a file. A simple example of how this command works will be like this. Imagine you wish to move the text "I like the Linux command line" into a file called interests.txt; then the corresponding command will beecho I like the Linux command like >> interests.txt

2. DIFF command

Thediffcommand compares the content of two files line by line. This is useful when you need to make program alterations, instead of writing the entire code again.

An example would bediff code1.txt code2.txt

3. JOBS command

Thejobs command will display all currently running jobs along with their status. A job is a process that is started by the shell.

4. KILL command

Just like in Windows, when we encounter an unresponsive program, we end the task from the taskbar. You can terminate these kinds of programs from Linux using thekillcommand.

There's quite a range of using the kill command which can be checked using thekill –lcommand.

Even though there is a list of 64 different commands, the most common ones are SIGTERM (15) and SIGKILL (9).

  • SIGTERM (15)— requests a program to stop running and gives it some time to save all of its progress. If you don't specify the signal when entering the kill command, this signal will be used.
  • SIGKILL (9)— forces programs to stop immediately. Unsaved progress will be lost.

Knowing the kill command is not enough to terminate the process without the PID number (process identification number). TO find out the PID, run the commandps ux

An example of terminating a process will look like this: kill -{kill number} PID

This command kill -9 2020 will terminate the process 2020.

5. WGET command

If you want to download something from the internet, you can do that using the Linux command line. Use thewgetcommand followed by the download link.

An example is shown below, where I downloaded the content of 1gbits.com, which will be saved as an HTML file.wget https://www.1gbits.com

6. PING Command

Like in windows, you can use the ping command to check the connectivity status to a server/internet. Here's an example where we checked if our system can connect to 1gbits.com and the response time. Note that the pinging will not stop automatically so to cancel it, simple use ctrl+z to cancel.

ping 1gbits.com

7. WHEREIS Command

Thewhereiscommand in Linux is used to locate the binary, source, and manual page files for a command. This command will search for files in the restricted set of locations (man page directories, binary file directories, library directories). The most common usage of this command is to find the executable files of a program, configuration files and the man pages.

The syntax is fairly simple: you type whereis followed by the name of the program.

For example whereis netstat will show the netstat executable and the location of the man page.

8. SERVICE Command

The service command run System V init scripts. The available syntax of using the service command is as follows:


service --status-all

service --help | -h | --version

To use the service command is not complicated at all. Let me give some simple examples (you will need root privileges):

  • To run a script:service sshd start
  • To stop an already running script:service sshd stop
  • To restart an already-running service:service sshd restart

9. ALIAS command

The command alias creates 'aliases' for your most commonly used commands. Aliases are like custom made shortcuts to represent a command.

To view all the default set of aliases, type in alias

To create a temporary alias is to enter the name you wish to use followed by a '=' sign and quote the command you wish to alias.

The syntax is as follows:

alias yourname="The custom command"

An example of using alias is as follows:

alias sus="cd /home/test/Downloads"

10. DF Command

Thedfcommand is used to display information related to the file system total space and available space.

The most common options for using the df command are as follows:

  • a –all: includes pseudo, duplicate and inaccessible file systems.
  • B –block-size=SIZE: scales sizes by SIZE before printing them.
  • h –human-readable: print sizes in the power of 1024
  • H –si: print sizes in the power of 1000
  • i –inodes: list inode information instead of block usage
  • l –local: limit listing to local file systems
  • P –portability: use POSIX output format

Here's an example of using the df command to display all file system information:

df -a

11. PASSWD Command

passwdcommand in Linux is used to change the user account passwords. The root user reserves the privilege to change the password for any user on the system, while a normal user can only change the account password for his or her own account.

To change your password, enter passwd

12. LPR command

The Linux commandlpr submits files for printing. The LPR Command transmits and manages print jobs.

When using the LPR command, you can use the following options:

  • E: Forcesencryptionwhen connecting to theserver.
  • P destination:Prints files to the named printer.
  • # copies:Sets the number of copies to print from 1 to 100.
  • C name:Sets the job name.
  • J name:Sets the job name.
  • T name:Sets the job name.
  • l: Specifies that the print file is already formatted for the destination and should be sent without filtering. This option is equivalent to-oraw.
  • o option:Sets a job option.
  • p: Specifies that the print file should be formatted with a shaded header with the date, time, job name, and page number. This option is equivalent to-oprettyprintand is only useful when printing text files.
  • r: Specifies that the named print files should be deleted after printing them.

13. CMP command

CMP command in Linux/UNIX is used to compare two files. It will compare byte by byte and will help you to find out whether the two files are identical or not.

  • When CMP is used, it reports the location of the first mismatch to the screen if the difference is found and if no difference is found the files compared are identical.
  • CMP displays no message and simply returns the prompt if the files compared are identical.

Advanced Linux Command List

1. ifconfig Command

Ifconfig stands for "interface configuration". It is used to view and change the configuration of the network interfaces on your system. Running theifconfig command with no arguments will display information about all network interfaces currently in operation.

2. CHOWN command

When it comes to the Linux infrastructure, all files are owned by a specific user. In the complete list of Linux commands the chowncommand enables you to change or transfer a file's ownership to a particular user.

Let me try to give you an example.

Imagine a user namedjohn,and the root user wants to provide the ownership of the file data.txt to john. The command will be as follows:chown john data.txt.The ownership of the file will be under the user john.

3. TOP command

Like the Windows task manager, thetopcommand will display a list of running processes and how much CPU each process uses. This is very useful to monitor system resource usage.


Linux is a multi-user system, which means that more than one user can use the same system simultaneously. To show how to add a user follow the screenshots that are shown below.

Adding a user max can be done by entering useradd max

To check if the user is added, you can enter the following: cat /etc/passwd

The user is created. Now to delete the user max, we can use the command userdel maxOnce deleted, check the list of users and you will no longer see the user max.

5. GREP command

Thegrepcommand is used to search for all the text in a given file. For example, grep dummy testdoc.txtwill search for the word "dummy" in the notepad file. Lines that contain the searched word will be displayed highlighted.

grep command

6. HEAD command

Theheadcommand will make your life much easier when going through documents. This command is used to view the first lines of any text file. By default, it will show the first ten lines of text.

The format will look something like this:head testdoc.txt

head command

7. TAIL command

This one has a similar function to the head command, but instead of showing the first lines, thetailcommand will display the last ten lines of a text file.

8. GCC command

GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++.

Syntax of gcc command isgcc [-c|-S|-E] [-std=standard]

Let's go through an example of using the gcc command.

gcc source.c

This will compile thesource.cfile and give the output file asa.out file which is the default name of output file given by gcc compiler, which can be executed using./a.out


There are many more best Linux commands that are out there, but we believe that with this Linux command list you can start getting familiar with the world of Linux. Here are some tips you can follow:

  • You can use theclearcommand to clear the terminal
  • EnterTABcan be used to fill the rest of the text of the command. For example, after you typecd docand press TAB, it will automatically fill it ascd documents
  • you can close the terminal by typing inexit
  • You can turn the computer ON and reboot the computer by using thesudo haltandsudo reboot

If you feel, Some more commands should be added to this list as per the interview point of view then you can comment on them via the given comment box, We will add them to your list to make you more familiar with Linux Environment.

People are also reading:

author img

Nisal N

Computers has always fascinated me since I was a kid and here we are. I love travelling for 2 reasons: the first one to see a new part of the world and second (the most important one) to experience the rich culture hidden among the country and people. I'm pretty good at cooking but very poor when it comes to baking.

Leave A Comment