Linux Common Operations and Commands

Last Updated At: 2025-11-26 11:12:11

1. What is Linux server Load Average?

Load is used to measure the workload of the server, that is, the length of the computer CPU's task execution queue. The larger the value, the more processes are running and waiting to run.

2. How to view the Linux server load?

You can execute the w, top, uptime, and procinfo commands, or access the /proc/loadavg file to view the Linux server load.
For installation of the procinfo tool, see the relevant documentation on software installation in a Linux environment.

3. What if the server load is high?

The server load (Load/Load Average) is displayed based on the length of the process queue. When the server experiences high load (it is recommended to use the 15-minute average value as a reference), it may be due to insufficient CPU resources, I/O read/write bottlenecks, insufficient memory resources, the CPU undergoing intensive computing, or other reasons. It is recommended to execute vmstat, iostat, and top commands to determine the cause of overload and to find the specific process that occupies a large amount of resources for optimization.

4. How to view the server memory utilization?

You can execute free, top (After execution, you can execute shift+m to sort the memory), vmstat, and procinfo commands, or access the /proc/meminfo file to view the server memory utilization.

5. How to view the memory size occupied by a single process?

You can execute top -p PID, pmap -x PID, and ps aux|grep PID commands, or access the /proc/$process_id (PID of the process)/status file to view the memory size, for example, /proc/7159/status.

6. How to view the services and ports in use?

You can execute netstat -tunlp, netstat -antup, and lsof -i:PORT commands to view the services and ports in use.

7. How to view the server process information?

You can execute ps auxww|grep PID, ps -ef, lsof -p PID, and top -p PID commands to view it.

8. How to stop a process?

You can execute kill -9 PID (PID indicates the process number), and killall program name (e.g. killall cron) to stop the process.
If you need to stop a zombie process, you need to kill the parent process of the zombie process by executing the command kill -9 ppid (ppid is the parent process ID, which can be obtained by executing the ps -o ppid PID command, for example, ps -o ppid 32535).

9. How to find zombie processes?

You can execute the top command to view the totals of zombie processes, and execute ps -ef | grep defunct | grep -v grep to find the information about specific zombie processes.

10. Why the server port cannot be enabled?

The enabling of server ports needs to be viewed from the operating system itself and the application program.
In Linux operating systems, ports below 1024 can only be enabled by root users, which means that you need to run sudo su – to obtain the root permission before you can enable the server port.
As for application problems, it is recommended to investigate the cause of failure through application startup logs, such as port conflicts (the port 36000 used by the server system cannot be occupied), configuration problems, etc.

11. What commands can be commonly used to view Linux server performance?

Command Name Description
top Process monitoring commands are used to monitor the overall performance of the system.
They can be executed to display information such as system load, process, CPU, memory, paging, etc. Shift+m and shift+p are often used to sort processes by memory and CPU usage.
vmstat System monitoring commands focus on virtual memory, and can also be used to monitor such information as CPU, process, memory paging and IO status .
For example, vmstat 3 10, which can be used to output the results every 3 seconds and can be executed 10 times.
iostat It is a tool used to output CPU status and IO status and to display the system's IO information in detail.
For example, iostat -dxmt 10, used to output detailed IO information in MB format every 10 seconds.
df It is used to check the system's disk space usage.
For example: df -m, used to display the disk space usage in MB.
lsof It can be used to list the files opened in the system. Since Linux is based on the file system, this command is very helpful in system administration.
For example:
lsof -i:36000, used to display the process using port 36000
lsof -u root, used to display programs running as root
lsof -c php-fpm, used to display the files opened by the php-fpm process
lsof php.ini, used to display the processes that have opened the php.ini file
ps Process view commands can be used to display detailed information of the process.
Common command parameter combinations are ps -ef and ps aux. It is recommended to use ps -A -o to customize the output fields.
For example:
ps -A -o pid,stat,uname,%cpu,%mem,rss,args,lstart,etime |sort -k6,6 -rn, used to display outputs by the listed fields and to sort by the sixth field.
ps -A -o comm |sort -k1 |uniq -c|sort -k1 -rn|head, used to list the process with the most running instances.

Other commonly used commands and files: free -m, du, uptime, w, /proc/stat, /proc/cpuinfo, /proc/meminfo.

12. What if Cron does not take effect?

The troubleshooting steps are as follows:

  1. Verify if crontab is running properly.

    1. Execute the crontab -e command, to add the following test entry.
    \*/1 \* \* \* \* /bin/date >> /tmp/crontest 2>&1 &
    
    1. Observe the /tmp/crontest file.
      If any problem is found, it is recommended to execute the ps aux|grep cron command to find the pid of cron, then execute the kill -9 PID command to end the cron process and execute the /etc/init.d/cron start command to restart cron.
  2. Verify that the script path in the cron entry is absolute.

  3. Check whether the user account running cron is correct, and check whether this account is included in /etc/cron.deny.

  4. Check the execution permissions of the script, the script directory, and the file permissions of the logs.

  5. It is recommended to run the script in the background and add "&" after the script entry. For example, \*/1 \* \* \* \* /bin/date >> /tmp/crontest 2>&1 &.

13. How to set a startup task for Cloud Virtual Machine (CVM)?

The Linux kernel startup sequence is as follows:

  1. Start the /sbin/init process.
  2. Execute the init scripts in sequence.
  3. Run the level script /etc/rc.d/rc\*.d, the value of * is equal to the running mode. You can view it in /etc/inittab.
  4. Execute /etc/rc.d/rc.local.
    Note:

    If you need to configure a startup task, you can configure it in the S**rclocal file in /etc/rc.d/rc*.d and you can also configure it in /etc/rc.d/rc.local.

14. Why is the server hard disk read-only?

The common reasons why the hard disk is read-only are as follows:

  • The disk space is full.
    You can execute the df -m command to check disk space usage, and then delete unnecessary files to free up the disk space (It is not recommended to delete non-third-party files. Confirm whether you need to proceed with deletion).

  • The disk inode resources are used up.
    You can execute the df -i command to view and confirm the related processes.

  • The hardware is faulty.
    If the issue with the hosting application cannot be identified through the above methods, submit a ticket for assistance in pinpointing the problem.

15. How to view Linux system logs?

  • The system-level log file storage path is /var/log.
  • Common system logs are /var/log/messages.

16. How to find large files in the file system?

You can follow these steps below to find them:

  1. Execute the df command to check the usage of disk partitions, such as df -m.
  2. Execute the du command to view the size of a specific folder. For example, du -sh ./*, du -h --max-depth=1|head -10.
  3. Execute the ls command to list files and file sizes, such as ls -lSh.

You can also execute the find command to directly view the file size under a specific directory, for example, find / -type f -size +10M -exec ls -lrt {} .

17. How to view the version of the server operating system?

You can view the system version by executing the following command:

  • uname -a
  • cat /proc/version
  • cat /etc/issue

18. How to set the timeout for connecting to the CVM via SecureCRT?

When SecureCRT is connected to the CVM, you can prevent disconnection through the following settings:

  1. Open SecureCRT Options.
  2. Select Session Options and click Terminal.
  3. In the Anti-idle box on the right, select Send Protocol NO-OP and set the time to every 120 seconds.

19. Why does deleting files on a Linux server not free up the hard disk space?

Cause:
After logging in to the Linux server and executing the rm command to delete files, and then executing the df command to view the hard disk space, it may be found that the available hard disk space has not increased after files are deleted. The reason is as follows: When you execute the rm command to delete files, other processes are accessing the file. As a result, if you execute the df command to view the space, the space occupied by the deleted files will not be released immediately.

Solution:

  1. Use root permission to execute the lsof |grep deleted command to view the PID of the process that is using the deleted file.
  2. Execute the kill -9 PID command to kill the corresponding process.