Today we are talking about the best useful command line for Linux server admins. If you read the whole article, you will know and learn a lot about that.
Best Useful command line for Linux server admin
The command line terminal, or shell, is a powerful tool for understanding activity on the server, performing operations, or modifying systems.
ls
ls lists the files in a directory. In container space, this command can help define the directory and files of the container image. In addition, it can help to check the permissions.
In the example below, when we check the permissions using ls -l, we realize that the permissions do not have “x” in -rw-r – r–, which is read-only and written.
$ ls -l myapp -rw-r–r–. 1 root root 33 Jul 21 18:36 myapp
tail
tail is used to view the last part of a file. For example, when we make a request to the Apache HTTP Server we use the tail command to check what happens to the logs.
Instead of following the log in real-time, we can use the tail command to view the last 100 lines of a file with the -n option.
$ tail -n 100 / var / log / httpd / access_log
cat
The cat command is used to check the contents of the file or to confirm the version of the application we have already created locally.
cat requirements.txt
Flask
flask_pymongo
Here, it checks whether the flask is listed as a dependency in the Python flask application.
grep
The grep command searches the file pattern. If we find a specific pattern in the output of another command, grep highlights the relevant lines.
We can use this grep command to search for log files, specific processes, and more.
env
env is used to set or print variables in the environment. When troubleshooting, we may find it useful to check whether the wrong environment variable prevents the application from starting.
$ envPYTHON_PIP_VERSION=9.0.1 HOME=/root DB_NAME=test PATH=/usr/local/bin:/usr/local/sbin LANG=C.UTF-8 PYTHON_VERSION=3.4.6 PWD=/DB_URI=mongodb://database:28071/test
id
We use the ID command to verify the user’s identity.
The following example uses Vagrant to test an application and isolate its development environment.
Once we log in to the Vagrant box, if we try to install the Apache HTTP Server the system says we cannot execute the command as root.
To test the user, run the id command:
$ Install yum -y httpd
Loaded Plugin: Fastest Mirror
We must be the root user to execute this command.
$ id uid = 1000 (vagrant) gid = 1000 (vagrant) groups = 1000 (vagrant) context =unconfined_u: unconfined_r: unconfined_t: s0-s0: c0.c1023
chmod
When we run the application for the first time on a host, we may get the error message “Permission denied.”
As can be seen in the example of ls, we can check the application permissions.
$ ls -l total 4 -rw-rw-r–. 1 vagrant vagrant 34 Jul 11 02:17 test.sh
Here we see that we do not have the right to run the application (no “x”).
In this case, chmod may modify permissions:
$ chmod + x test.sh [vagrant @ localhost ~] ls -l Total 4
history
It shows the history of commands we have run since the beginning of the session. We can use the history command to log which commands we used to troubleshoot the application.
If we want to execute a command in the previous history, we need to run ‘!’ Before the command number runs again.
ip
The ip command shows network devices, their routes, and a means of manipulating their interfaces.
We use this command to read the information on the interfaces:
# ip a