15 Commands You Should Know When Working With a Linux Server

Tram Ho

In a booming world with new tools and diverse development environments, learning some basic sysadmin commands is a must for any developer or engineer. Specific commands and packages can help developers organize, troubleshoot, and optimize their applications and – when something goes wrong – provide valuable trilogy information to operators and systems.

In this article I want to share some useful commands that I often use when operating with a Linux server.

1. history

Imagine when you manipulate and use a lot of commands and make the server error and now you do not know which command you have used the wrong command, the history is the command that will help you. The history command will list the commands that you have used.

Also when you want to reuse a certain statement without having to retype or use ! Number . If you want to use df -h , type ! 2 .

2. chmod

Unlike other operating systems like Windows .. when you manipulate a file on Linux many times you will get a permission denied error, which means you are not having the right to execute with file or file. there. Use the chmod command

w: is the permission you want to assign to the file (for example: w is write permission, r: read permission ..)

3. du

To retrieve more detailed information about which files are using disk space in the directory, you can use the du command. For example, if you want to find out which logs take up the most space in / var / log, you can use du with the -h (human readable) option and the -s option for the aggregate. ruler.

The example above shows the largest directory in / var / log is / var / log / Audit

4. df

You can use df (show free disk space) to troubleshoot disk space. When you run your application on a container coordinator, you may receive an error message indicating a lack of free space on the container server. Although disk space must be managed and optimized by sysadmin, you can use df to find out available space in the directory and confirm if you are really running out of space.

The -h option prints out information in human-readable format. By default, as in the example df gives results for everything in the root directory, but you can also limit the results by providing a directory as part of your command (such as df -h / home).

5. ip

The subcommand address (or ip a for short) displays your application server’s interfaces and IP addresses. You use the ip address to verify the host or host’s IP address. For example, when your container is attached to two networks, the ip address can show which interface connects to which network. For simple testing, you can always use the ip address command to get the server’s IP address. The example below shows that the web layer container has an IP address of on the eth0 interface.

6. tail

For developers who have to debug, viewing the log of a file is not uncommon. However, we cannot sit down to read every line in the log. Sometimes just want to see the latest log recorded in the file. The tail – f statement will help us with this.

The -f option indicates the “follow” option, which outputs the log lines as they are written to the file. An example has a background script that hits the endpoint every few seconds and logs the request. Instead of tracking the log in real time, you can also use the extension to see the last 100 lines of the file with the -n option.

7. ls

A legendary command that everyone who uses Linux has probably used it. ls lists the files in a directory. Sysadmins and its developers issue this command quite often. In the container space, this command can help locate your container image files and folders. Besides looking up your files, ls can help you check your permissions. In the example below, you cannot run myapp due to a permission issue. When you check the permissions using ls -l , you realize that the permissions don’t have “x” in -rw-r – r–, can only be read and written.

8. curl

This command is extremely useful when we want to test if we can connect to another url (end-point). For example, imagine your application gets an HTTP 500 error saying it cannot access the MongoDB database:

9. grep

The grep command is used to search for text. It searches for certain files for lines containing matches that match given strings or words. This is one of the most useful commands on Linux and Unix-like systems. Let us see how to use grep on Linux or Unix-like systems.

10. ps

The ps command, part of the procps-ng package, provides commands that are useful for investigating a process ID, displaying the status of a running process. Use this command to identify a running application or to validate an expected process. For example, if you want to test a running Tomcat web server, you use ps with its options to get Tomcat’s process ID.

11. pwd

When you want to check the current path in the folder you are working in, use the pwd command. Use the pwd command to find out the path of the current working directory (directory) you are in. This command will return an absolute (complete) path, which is essentially the path of all directories starting with a forward slash (/). An example of an absolute path is / home / username.

12. cat

cat is one of the most frequently used commands in Linux. It is used to list the contents of a file on standard output (sdout). To run this command, type cat, followed by the file name and its extension. For example: cat file.txt.

13. kill

If you have an unresponsive program, you can end it manually using the kill command. It sends a certain signal to the malfunctioning app and instructs the app to end itself.

There are sixty-four signals in total that you can use, but people typically only use two:

SIGTERM (15) – asks a program to stop running and give it some time to save all of its progress. If you do not specify a signal when entering a kill command, this signal will be used. SIGKILL (9) – forces programs to stop immediately. Unsaved progress will be lost. Besides knowing the signals, you also need to know the process code (PID) of the program you want to kill. If you don’t know the PID, just run the ps ux command.

After knowing the signal you want to use and the PID of the program, enter the following syntax:

14. top

As a terminal equivalent to the Task Manager in Windows, the top command displays a list of running processes and how much CPU each process uses. It is very useful for monitoring system resource usage, especially knowing which processes need to be terminated as it consumes too many resources.

15. cp

Use the cp command to copy files from the current directory to another. For example, the command cp scenery.jpg / home / username / Pictures will create a copy of scenery.jpg (from your current directory) into the Pictures folder.


Basic Linux commands help users perform tasks easily and efficiently. It may take a while to remember some of the basic commands, but nothing is impossible if you practice a lot.

The article is traced from:



Share the news now

Source : Viblo