Mastering Linux seems confused, unlike the GUI in modern applications, Linux has all the power using the terminal with Linux commands and tools. It is capable to handle, and do more than you expect. Let’s learn basic linux commands to get you started and then advanced linux commands. These linux shell commands can be useful during your exams, school or for a job interview etc. In the terminal, you need to follow some specific instructions to handle the tools, and tasks. These instructions are commands, just follow these advanced & basic linux commands which are powerful to work on linux.
In this post, you will find most useful linux commands list which helps you to ace Linux from Newbies to Advanced. I have collected the top Linux commands, which I have listed most useful and handy linux commands with examples for you to understand easily.
Starting with Basic Linux commands:
lsblk linux command
this basic linux command will list the block devices by their specified name, it reads the sysfile system and the udev db to capture the information. open your terminal and type this command, the output is show in tree like design format.
the present working directory command will print your current directory with it’s path.
cd linux command
Change Directory command. As soon as you discovered the pwd, then you need the cd. This command is used to navigate to whichever directory you want. you have to specify the “/” and then the folder you want to go, for example:
The command “ls” stands for List Directory Contents, it basically means to list the files of a specified folder. This command has some additional functionalities.
will list the contents of the folder in the long listing order
will list all the files, including the hidden files
this will list the files that were edited recently or modified and list them at first.
whoami linux command
This command will display the current user login information.
Also Check: Funny Linux Commands and Linux Tricks
md5sum linux command
commonly called as md5 hash, it will verify the integrity of the file, to avoid the duplicates with same copy of the file. For example
touch linux command
A command that helps you quickly create files, or you can also use ” touch” on existing files. you can also create multiple files at same time, for example
we will explore more about touch command later
clear linux command
– it will clear the terminal for you.
uname linux command
literally unix name, it will print the information about your computer, like machine name, operating system and kernel. The more extended version of this command is uname -a, which outputs more detailed information.
rm linux command
will remove the file
linux time command
The linux time command is not just the command that shows the time. It has many functions, it performs by given arguments. For exapmle, you know the CPU run time, sysytem run time etc. Let’s see how we can use this command, follow the systax format below.
time command example: calculate the disk space you ” df ” linux time command
the command df will calculate the disk space, and reports how long it took for the process to terminate. Some more linux time commands examples
- csh – The C shell command interpreter
- date – Output the current date and time
- timex – Report process data and system activity for a specified command
linux date command
I will take you little deep about the date and time commands in linux. The linux date command is very important, most of the functions depend on it. Like this command keeps track of all the sessions, process times, and the server times. Let’s follow some list of commands used with the Linux date command.
Set time and date from the linux command line:
Linux check date command
to set the timezone in linux – We are using america as our timezone.
to choose other timezone, browse from the following command and choose your timezone
There is another method to set timezone is linux.
On some linux distributions (for example, Ubuntu), the timezone can be modified by /etc/timezone file.
For example, your current timezone might be US Eastern time (New York) as shown below.
To change this to US Pacific time (California), modify the /etc/timezone file as shown below.
Also, set the timezone from the command line using the TZ variable.
Set hardware clock
wondering what is hardware clock? It is the clock that runs in you system hardware even when your pc is not running. It receives power from the internal battery. We have hardware clock and system clock, let’s dive in.
to check the hardware clock – enter the following command in your terminal
that will output:
Now let’s check the System Clock
Moving to Advanced Linux Commands:
Now it’s time to become a Linux System Admin. Let’s learn the Advanced Linux Commands from our complete list of useful Linux commands with examples.
sudo linux command
super user do, the command allows the user to perform the executions as super user with security privileges of another user.
this command, will actually help the user to login as super user.
Make directory, this command is used to create a directory or folder.
it stands for Change File mod bits” this command can change the permission of a file, folder or script. We have 3 types of permissions for a file, such as ” Read (r)=4, Write(w)=2, Execute(x)=1 ” so if you want to give read permission to a file, it will be assigned a value of ‘4’, and for write permission, a value of ‘2’, and for execute permission, a value of ‘1’. If you need to add both permission such as read and write, then 4+2= 6 is to be given.
Let’s say you are the owner of a file named thisfile, and you need to configure it’s permissions, then:
- the user can read, write, and execute it;
- members of your group can read and execute it; and
- others may only read it.
This terminal command will do the trick:
In this example, i have showcased the utility of symbolic permissions notation. The letters u, g, and o means for “user“, “group“, and “other“. The equals sign (“=“) means “set the permissions exactly like this,” and the letters “r“, “w“, and “x” stand for “read”, “write”, and “execute”, respectively. The commas help identify the different classes of permissions, and there are no spaces in between them.
Another example, assume that now permissions need to set for 3 different kinds of user groups, such as
Here, the permission of root is rwx (read,write and execute)
will add the executable permission for the user to cda.sh
will remove the write permissions for other users
will make the cda2.sh readable and executable to everyone.
The linux command chown stands for change file owner and group. In Linux every file is associated with an owner and a group, to change the owner of a particular group or a file, we use the chown and chgrp commands. First, let’s talk about the chown command.
the above Linux command will make user1 as the owner of the file1 but the group owner will not be changed.
this will change the owner ship of multiple files to lucas user.
There are more functions available for the chmod terminal command, we will discuss about it in another post.
linux tar command
This command helps users to create archives, it supports multiple number of file formats. Check out how the linux tar command works:
tar -jxvf abc.tar.bz2
Here’s what we actually did:
from the command:
-c: Create an archive
-z: Compress the archive with gzip
-v: it can be used to display progress in the terminal while we run the compression process.
-f: allows you to specify the filename of the archive
-x: it is replaced by c to extract the file
-j: if the file is bzip2 compressed file, then replace the z with j.
A ‘tar.gz’ means it is compressed by gzipped. And ‘tar.bz2’ is compressed with bzip.
apt package installer linux command
It stands for Advanced Package Tool, which is found in the Debian based Linux distributions such as Ubuntu, kubuntu etc.., it will help the system to install, download, and update new packages by using the Linux command line. For example,
will perform an update of all the packages which are installed to the newest version.
linux shutdown command
to shut down the linux system from the terminal, first you must sign in or be a “root” or “su” user. Then type
Then wait some time for the linux shutdown command to run, this process will take few minutes to be executed. And then the Linux system will shutdown.
Find command in Linux
the linux find command is available on all linux distros where you don’t need to install the additional package. This command is very handy and important command in linux.
the syntax of find command in linux:
The find command in Linux is so powerful that it can let you do various activities. With the help of find command in Linux you can List all files in present and sub directories , to search specific directory or path and to manage the files behavior etc. We will discuss more about the linux find command in our next article. So, stay tuned.
linux cat commands
it means concatenation, The linux cat command is one of the most frequently used in Linux systems. It will display text files on the screen, combine text files and print it on standard output. For example
This Linux command will display the contents of files.
Here it will do the cat (concatenate) the multiple files and prints the content of the file on standard output. The characters “>>” and “>” are used to append the output to a file and not on the standard output. it is always better to use the “>>” instead of “>” for security reason.
linux zip command
the zip file is a compression utility that compresse the files and folder into one file with less size. which ends with extension .zip. In order to use the zip command in linux to Zip and unzip a file, let’s follow below
To compress the files using linux zip command. check the below exmple
To Uncompress the zip file in linux
it will unzip the file content in present working directory.
linux mail command
You can actually send an email through your linux command line from a server or automate an email with all the shell scripting or web applications. Let’s see how to use the linux mail command
Install linux mail command
The installation of mail command on different packages. Following are the list:
1) gnu mailutils
Each package have their own way of funtions and options. In our case we have choosen heirloom-mailx package which enables the connection of an external Simple Mail Transfer Protocol (SMTP) server to send messages.
Install mail command on CentOS/Redhat:
$ yum install mailx -y
The following command will allow you to send an email with the subject. The option ‘s’ allow you to an send email with subject followed by the recipient address.
$ mail -s “Enter the subject” firstname.lastname@example.org
Don’t forget to add the CC (Carbon Copy) if required.
After the completion of required fields press Ctrl + D, this will give an output EOT.
Send message from a file
The content of the message can be included from a file also.
$ mail -s “The Subject” email@example.com < /root/testemail.txt
Messages can also be including by using echo command and piping it.
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” firstname.lastname@example.org
We do also have option to send the email to multiple recipients.
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” email@example.com,firstname.lastname@example.org
CC and BCC
Blind carbon copy (BCC) and carbon copy (CC) address can also be attached within a command in Linux.
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” -c email@example.com,firstname.lastname@example.org
Specify From name and address
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” –r “Info<Info@slashbug.com>” email@example.com
Specify “Reply-To” address
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” replyto= firstname.lastname@example.org email@example.com
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” replyto= “firstname.lastname@example.org” email@example.com
The option –a is used to add an attachment along with the email.
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” –r “Info<firstname.lastname@example.org>” –a /path/to/file email@example.com
Feel free to contact me in case of help.
grep command in linux
If you are bored, then check out this grep command. It can make your work easier by helping you print a specified pattern of your search. grep command searched the given file for lines containing a match to your given text or strings. This command is to installed as package on your linux distro, you can easily install via package manager apt-get on debian and yum on RHEL/CentOS/Fedora. Let’s first install the command:
On Debian Linux
Using grep for search files.
To search /etc/passwd file for the user alex, enter the following command.
$ grep alex /etc/passwd
You can force grep to ignore word case i.e match alex, ALEX, Alex and all other combination with the -i option:
$ grep -i “alex” /etc/passwd
linux source command
Wondering what is the linux source command? It is a bash shell built-in command that executes the content of the file passed as an argument, in the current shell. It uses the symbol “.” (period).
source filename [arguments]
linux network commands
It’s important to talk and work on the linux network commands. As every device and computer is somehow connected on the network. They might be at your home, office, small or large networks etc.
check out the list of handy Linux network commands:
|Display and manipulate route and network interfaces.
|It is a replacement of ifconfig command.
|Network troubleshooting utility.
|Similar to traceroute but doesn’t require root privileges.
|To check connectivity between two nodes.
|Display connection information.
|It is a replacement of netstat.
|Query DNS related information.
|Find DNS related query.
|Shows and manipulate IP routing table.
|Performs DNS lookups.
|View or add contents of the kernel’s ARP table.
|Used to configure wireless network interface.
|To identify a network name.
|curl or wget
|To download a file from internet.
|Combines ping and tracepath into a single command.
|Will tell you about the website’s whois.
|Tells whether a cable is plugged in or not.
linux history command
When working on Linux, it is important to access the history to recall your progress. We use history comand frequently to check history of commands and executed processes to get info about what command, which command and which user executed the command. You can track the time and date of the executed command, which may help you in the security audit scenarios. Here I will talk only the main functions of the history command. If you want to know all the commands, functions used in the history command then please let me know in the comments below.
List Last/All Executed Commands in Linux
With the history command, you can see complete list of last executed commands with line numbers.
1 PS1=’\e[1;35m[\u@\h \w]\$ \e[m ‘
2 PS1=”\e[0;32m[\u@\h \W]\$ \e[m “
3 PS1=”\u@\h:\w [\j]\$ “
4 ping google.com
5 echo $PS1
6 tail -f /var/log/messages
7 tail -f /var/log/messages
linux sleep command
Well, the linux sleep command is not very useful most of the time; it does have an important purpose that is to pause a bash script. If you want to lock up your terminal window but as pasrt of a script then there you go, use the linux sleep command. Let’s see how we can use the Linux sleep command in the terminal to pause a bash script.
Enter the following in the terminal window
the above command will make your terminal pause for 5 seconds.
you can specify the delay time by changing the argument syntax.
- s – seconds
- m – minutes
- h – hours
- d – days
Make sure that you practice all these Basic & Advanced Linux Commands in order make your self comfortable and easier for you, and stay tuned for more. you can check my previous guide on, what to do, if you are bored and have a computer?