20 Linux Commands Every System Administrator Should Know!

Posted on September 14th, 2022

When Linus Torvalds created the Linux operating system, he would have never thought that this OS would soon become the market leader, and would be adopted by almost every multinational company for managing their applications.

People who don’t have any background in coding or IT generally use operating systems like Windows and Mac, but still Linux has achieved its dominance in the operating system space. 

The significance of Linux in the world of open source software and information technology companies cannot be denied.

Most companies want to lower down their expenses and want to complete projects with lower cost, because of this reason they prefer using Linux over Windows operating system or Mac, as they require a valid key to operate this OS.

Aspiring IT Engineers can educate themselves with Linux before learning any of the big Technologies like Machine Learning, Data Science, Python, and Java.  All of these latest technologies have their dependency on Linux and almost all of them run on the top of Linux OS.

This operating system is so vast that companies have to hire Linux administrators for carrying out the Linux operations. In this blog, we will discuss commands which every Linux administrator should know to make progress in his or her career. 

Types of Linux Operating Systems

Basically, there are various types of Linux operating systems. To give you an example, Ubuntu, Red Hat Linux, Fedora, and many more. These operating systems are distinguished on the basis of their systems.

There are two Linux systems, the first one is the Symbian-based operating system and the second is the Debian-based operating system.

Out of the above mentioned operating systems, Ubuntu is Debian based and Red Hat Linux and Fedora are Symbian-based operating systems. 

Given that the core of all of these operating systems is the same but there are differences in the way some commands are executed.

The reason why there are many types of Linux operating systems available is because Linus Torvalds created the first Linux OS as an open-source program. With time multiple companies have created their own version of Linux as it was an open source program.

But anyways enough about Linux, now we will focus more on the important commands of Linux.

20 Most Important Linux Commands Every System Admin Should Know [With Examples]

The graphical interface of Linux restricts the user to use this OS to its full capacity. Because of this reason, all the system admins or Linux administrators use the command line interface to explore the pseudo power of Linux. 

Here I have created a list of the most important Linux commands without which Linux administrators cannot survive.

1. Tail command in Linux

If you want to find out if the application is running smoothly or showing some errors you can check the logs of the application. When you use the cat command to view logs, the output will contain the whole file. Sometimes the log files are large and you want to check recent logs only. In that case, Tail command will be your friend.

The tail command is used when you want an elaborated version of the logs to understand the problem in a better way. Here are few examples of the tail command.

1. Display last 100 lines of a file.

$ tail -n100 example.log

2. Display last 100 lines of file and keep showing new inputs.

$ tail -f -n100 example.log

3. Display file name if you want to see multiple log files at once.

$ tail -v example.log example2.log

Tail command will help you a log debugging with log files.

2. env in Linux

If an application asks you for the password now and then so that it could be executed then create an environment variable of that password or path. By doing this we don’t have to type a password every time because we have stored that password in our variable. 

What if there are many environmental variables and you have forgotten a few of them? In this scenario, we use the env command to list down all the environment variables that are available in Linux.

I have set the value of the $HOME variable as its path. You can modify the path or condition according to different scenarios.

3. netstat command in Linux

There are various command dependencies in Linux. Some of them are preinstalled and you don’t have to install them, on the other hand, there are few commands which require the installation of additional tools. 

Linux has its network system just like Windows and Mac. For Windows, if you want to check the networking settings will have to go to the control panel. But in the case of Linux, the command netstat will show all the networks that are running on Linux.

netstat command will not only show network type and local address but also show all the process activities that are running in the background.

Command for checking network – $ netstat -a

4. “df -h” command in Linux

Each operating system has storage attached to it that’s why the OS can boot and start. In the case of our laptops and computers, physical hard disks are attached so that the OS can function properly. 

We can check the disk space and storage on windows and mac with just a right click, but in the case of Linux CLI, we have to use the df – h command to get a clear idea about the space utilized. 

If you are in a situation wherein your application is not installing and the logs generated are showing low disk space then you might have to mount additional storage to the OS so that the application can get installed.

With the use of df - h command you can know the files and their size occupied. Also, this command shows how much free space is left in the OS.

Command to find out disk space – $ df -h

5. “ls -la” command in Linux

Every file and repository in Linux has some permission attached to it. Each of these permissions will signify whether the file or repository can be opened or is rewritable or is it possible to make changes.

If the file or the repository has insufficient permissions then operations will not be properly executed in that file, as it is missing the permissions. 

In this situation changing the file permissions is a quick solution. To check what permissions the file or repo is carrying, the ls -la command is used.

Command to check file or repository permission – $ ls -la

6. History command in Linux

As we have discussed before, Linux uses CLI commands for performing basic as well as advanced tasks. But the thing is, Linux is a very big OS so it is impossible to remember every command. 

If you want to find out the previous commands which were executed before then you can use the history command.

Command to use to show history – $ history

7. Curl command in Linux

Generally, if we want to access any website we use browsers like Chrome, Safari, Firefox, etc. But what if we want to access a website in Linux and there are no browsers present?  

To tackle this, Linux comes up with its own CLI-based  browser, through which it can access any website available on the internet. 

Below I have given an example of how I was able to access google.com with the help of the curl command. 

If this command is not present in your operating system then you can execute the below-given command and hence can access websites through Linux CLI.

Command to install curl – $ sudo apt install curl

Syntax of a curl command – $ curl examplesite.com

Curl command comes with a lot of different options to modify the output however you want. You can use man curl command to learn all the options available with the curl command.

8. Grep command in Linux

The grep command in linux allows you to filter through files. So, you can find whatever you want in a single or multiple files. You can also pass regular expressions to find matches. It is also possible to pass output of a command to grep as an input.

For example, as you can see there are so many processes running but if I want to search for a particular process and highlight it, I can use the grep command.

I have used ps -ef | grep 10 command in the above example. 10 is a pid process which I was looking for.

9. SSH command in Linux

This is perhaps one of the most used commands in Linux. We use ssh command to connect to other Linux operating systems. In fact, to use this LINUX operating system I have made an ssh connection first. 

Whenever you launch a Linux server with the help of any Cloud Service they provide you an SSH string that you can use to connect to your Linux operating system.

The basic SSH command requires username, password and the IP address of the server. For example, the following command allows you to log in to the server with any authentication method possible. If SSH key is not set, and if server allows, you can also log in with password. In most cases, you can log in to a server using password.

$ ssh [email protected]

The following command allows you to log in via a specific SSH key.

$ ssh username@hostname -i /path/to/ssh/key.pem

Once connected with a server using SSH, you will see the similar output as the following example.

10. Chmod command in Linux

The chmod or change mod command is used in linux for changing the file and folders permissions. A user can modify permissions like read, write or execute for a particular file or repository. 

File permissions are different for users.

There are mainly three types of users in linux: 

  1. owner user 
  2. group user 
  3. other user

There are three modes while giving file permissions.

  1. Read – r
  2. Write – w
  3. Execute – x

Let’s see an example.

In the above example I have changed the file permissions of LICENSE to 777 i.e read, write, execute for all the three users.

11. chown command in Linux

In simple words chown command stands for change ownership. The chown command can change ownerships of files and repositories. Each file or repo in Linux has one user owner and one group owner. 

The below syntax is followed for changing the user permission

$ sudo chown newuser filename

The below syntax is followed for changing group user file permission

$ sudo chown :groupuser filename

You can also combine both to change ownership for both. For example, sudo chown username:groupname filename.

12. rm command in Linux

The rm command is used to delete files and directories in the Linux operating system. Let’s say you have an unwanted file which was installed during the installation and you want to get rid of that file. Then we use the remove command. The syntax for removing file commands is given below with an example.

Syntax – rm -rf filename (rf stands for remove forcefully)

As you can see in the following example, If you want to delete a file, you can use rm command in linux.

13. gzip command in Linux

Let’s say that if I want to compress a file, then I can use the gzip command. This command is used when we have to mostly transfer a file from one operating system to the other and reduce the file size as well.

The syntax for using this command is given below along with an example.

Syntax – gzip filename (To zip a file)

Syntax – gunzip filename (To unzip a file)

In the above example I have first compressed the LICENSE text file with the gzip command. Now if I want to unzip that text file again then I will have to use gunzip command.

14. wget command in Linux

Wget is a networking tool which you can run on the command line to download files and folders from the internet servers. Many times while installing packages from web servers we use wget command. Wget can download any file from http, https and FTP servers.

It can download an entire website with just one command.

In the example above I have downloaded index.html from google.com.

Syntax – wget URL

Example – wget google.com

You can also use wget with options. Just like curl, wget comes with many options to modify the output. You can run the man wget command to see and learn all the available options.

15. mv command in Linux

If we want to move a file or a directory from one location to another, that is if we want to change the path of a directory we can use mv command.

Not only this but if we want to rename a particular file or directory mv command is used.

In the above example I have renamed the “xyz” text file to “abc file”.

16. useradd command in Linux

If you are working on a project then most probably you will have to work on a new user rather than the root user for security purposes. 

So every time when you launch a new LINUX operating system you will have to create a separate user for the project. The reason why this command has made it into this list is because every now and then you will have to create a user for yourself and for other users as well.

Here is the exact syntax of for useradd command.

Syntax : sudo useradd newuser

Syntax: sudo passwd newuser

After using passwd command it will ask you for a password which you want to assign to the user which you have created.

17. mkdir command in Linux

If you want to create a directory in the Linux operating system then mkdir command is used. While performing many operations there will be a need wherein in a repository is needed.

so we use this command. The syntax for using this command is given below. An example has been provided.

Syntax – mkdir name_of_directory

Example – mkdir newrepo

18. Nano editor in Linux

There are multiple text editors available in Linux but out of all the text editors nano text editor is my favorite. Using nano is very easy, it’s a user friendly text editor with easy commands. The most recommended editor is vi editor. But, if you are just getting started with Linux, nano will be easier for you.

You can create a new file using nano or edit an existing file using the following command.

$ nano filename.txt

If the file exists, You can modify it. If it does not exist, you can create a new file. Once the editor is open, you can add contents to the file.

If you want to exit a file then press ctrl + X.

It will ask you whether to save or not, if you don’t want to save then press N. If you want to save then press Y.

19. “./” – Execute shell scripts in Linux

Often you will be asked to create a shell script for making tasks easier and for automation purposes. Let’s say that you have created a shell script and now want to execute it. What would you do?

In scenarios like this we use the ./ command into consideration. Below I have mentioned an example wherein I have created a shell script, and I am executing it.

20. apt command in Linux

Last but not the least, apt command. Apt is a package installer in Ubuntu operating system. Every type of linux has its own package installer. For example, in the case of Redhat Linux we have yum as a package installer. 

The syntax and example for using the apt installer is given below.

Syntax –  $ sudo apt install name_of_package

Example – $ sudo apt install nginx

Summary

In this blog, we have covered the most advanced and most used commands that a Linux administrator should know.  

There are hundreds of other commands as well which are as important as these commands are, but covering all of them in just one single post would not be possible. We will cover other Linux commands in the next article.

We have talked about how Linux has revolutionized operating system space and also talked about the importance of Linux administrators in a company. To add furthermore, we have also covered the most important Linux commands that a Linux administrator should know. 

Leave a Reply