Common commands for Linux server systems

Linux is widely used in the field of server operating systems, and the vast majority of Linux server operating systems do not provide a graphical user interface by default. The server administrator needs to interact with the Linux server through the command-line interface. This article will introduce commonly used commands in Linux systems.
supervisor process
ps
Command Introduction
The ps command is an abbreviation for Process Status, used to view a snapshot of the running processes in the current system.
Common parameter description
parameter
meaning
-A
Display all programs.
-a
Display all programs under the current terminal.
-e
The effect of this option is the same as specifying option "A".
-f
Display UID, PPIP, C, and STIME fields.
-u
Display program status in a user centric format.
-U
List the status of programs belonging to the user, or specify them using a username.
-x
Display all programs without distinguishing between terminals.
explain
More parameter explanations can be viewed by running man ps.
Example usage
View all process information.

ps -ef
Search for program process information using program name keywords (specify - e, - f parameters).

ps -ef | grep <key_word>
Please replace<keyw_ord>in the above command with the keyword you specified.
Search for program process information using program name keywords (specifying - a, - u, - x parameters).

ps -aux | grep <key_word>
Please replace<keyw_ord>in the above command with the keyword you specified.
View process tree information.

ps -ejH
View process information containing thread data.

ps -eLf
Display thread information using custom field formats.

ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
View the information of the specified PID and indicator. In the example, PID is 1 and the indicator information is comm=.

ps -q 1 -o comm=
top
Command Introduction
The top command provides a dynamic real-time view of processes running on a Linux system, displaying an overview of the system and a list of processes currently managed by the Linux kernel.
Common parameter description
Parameter options
explain
-d
Specify the refresh frequency for the top command.
-p
Specify PID to monitor the status of the specified process.
-s
Run the top command in safe mode, which will remove potential hazards associated with interactive mode.
-i
Make top not display any idle or dead processes.
-c
Display the complete command instead of just the command name.
Description of Resource Monitoring Fields
The following figure shows some monitoring fields and their values, which may vary depending on the sampling period. This chart is for reference only, and specific data should be based on your actual data.
image
The main parameters are described as follows
Description of System Summary Information and Process Indicator Monitoring Fields
Example usage
View system indicators according to the specified collection frequency
Run the following command to display system indicators at the specified collection frequency. The specified collection frequency in the example is once every 3 seconds.

top 3
explain
Execute the top command, and by default, the system indicators will be displayed with a collection frequency of 5 seconds.
Customize the top command indicator display interface
By default, the top command displays indicators such as system summary information and process indicator monitoring field descriptions. To modify the displayed indicator interface, you can press the f key in the top interactive command interface to filter the indicator view you need.
image
In the view field management interface, please refer to the table below for related operations.
Key
explain
↑,↓
Select fields.

Select the entire column, and then use the up and down keys to move the display position of the entire column.
Space
Choose whether to hide or display the field, with * indicating display.
s
Set the column where the current cursor is located as a sorting sequence.
q
Exit the view field management interface.
Interactive mode using the top command
After running the top command, the system will enter interactive mode. In this mode, users can interact with commands through buttons. Please refer to the table below for the commands supported by the interaction mode.
Key
explain
one
Display the metric status of each logical CPU.
u
After pressing the u key, enter the Linux system username to view the processes related to that user.
E
Switch the measurement units of memory indicators between Kib, MiB, GiB, TiB, PiB, and EiB.
x
Display the sorting sequence.
y
Display running processes.
?
Display help information.
kill
Command Introduction
The kill command is used to manually terminate a process in Linux.
Common parameter description
parameter
explain
-l
List the names of available signals.
-L
List the signal names in the table.
Example usage
Kill all processes that can be killed.

sudo kill -9 -1
Display the signal name represented by signal number 11.

sudo kill -l 11
List all available signals in the table.

sudo kill -L
Terminate the process with the specified PID.

sudo kill -9 <PID>
Please replace the<PID>in the above command with the process PID you specified.
killall
Command Introduction
The killall command is used in Linux to terminate a process by its name.
Common parameter description
parameter
explain
-g
Kill processes belonging to the process group.
-i
Interactive mode, seeking confirmation information before killing the process.
-v
Report whether the signal was successfully sent.
Example usage
Kill the top process.

sudo killall top
View system information
During the use of Linux instances, the uname command can be used to query system information.
uname
Command Introduction
The uname command is used to output system information.
Common parameter description
option
explain
-a
Output all information.
-s
Output the kernel name.
-n
Output the host name of the network node.
-r
Output the kernel release version.
-v
Output kernel version information.
-m
Output the hardware name of the machine.
-P
Output processor type.
-i
Output hardware platform information.
-o
Output operating system information.
Example usage
View all system information.

uname -a
View Management Disk
df
Command Introduction
The df command is used to report the usage of file system disk space.
Common parameter description
option
explain
-a
Contains pseudo, duplicate, and inaccessible file systems.
-B
Convert the block size to the specified size before outputting.
-h
Display size as a power of 1024 (e.g. 1023M).
-H
Output size to a power of 1000 (e.g. 1.1G).
-k
Equivalent to block size=1K.
-l
Only list local file systems.
-t
Only display file system information of the specified type.
Example usage
View disk space usage in MB units.

df -BM
The example of the display result is as follows.

Filesystem 1M-blocks Used Available Use% Mounted on
tmpfs 742M 22M 721M 3% /run
/dev/vda3 39943M 2542M 35556M 7% /
tmpfs 3708M 0M 3708M 0% /dev/shm
tmpfs 5M 0M 5M 0% /run/lock
tmpfs 742M 1M 742M 1% /run/user/0
lsblk
Command Introduction
The lsblk command is used to list block device information.
Common parameter description
parameter
explain
-a
List all devices, including empty devices and memory disk devices.
-b
The SIZE column uses bytes as output.
-f
The output information includes the file system.
Example usage
View block device information, including file system information.

lsblk -f
The example of the display result is as follows.

NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
vda
|-vda1
|-vda2 vfat FAT32 6175-F96E
`-vda3 ext4 1.0 df02e0a1-d28d-41b1-99c2-58f2b684cc79 34.7G 6% /
blkid
Command Introduction
The blkid command is used to view block device attribute information.
Example usage
View block device attribute information

blkid /dev/vda
The example of the display result is as follows.

/dev/vda: PTUUID="bdee1c7f-46fc-4838-9a74-9exxxxxxxxaf" PTTYPE="gpt"
fdisk
Command Introduction
The fdisk command is a Linux partition table manipulation tool.
Common parameter description
parameter
explain
-l
List the partition table information for the specified device.
-u
Display the information of each partition in the partition table in the form of sector numbers rather than cylinder numbers.
Example usage
Check the partition status of the device.

sudo fdisk -lu
The example of the display result is as follows.

Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: BDEE1C7F-46FC-4838-9A74-9E57F8FD63AF
Device Start End Sectors Size Type
/dev/vda1 2048 4095 2048 1M BIOS boot
/dev/vda2 4096 413695 409600 200M EFI System
/dev/vda3 413696 83886046 83472351 39.8G Linux filesystem
mount
Command Introduction
The mount command is used to mount a file system.
Common parameter description
parameter
explain
-a
Mount all file systems described in the/etc/fstab file.
-L
Mount the partition with the given label.
-r
Mount the file system in read-only mode.
-w
Mount the file system in read-write mode.
-U
Mount the partition with the specified UUID.
Example usage
Mount all file systems configured in fstab.

sudo mount -a
Mount the specified file system in read-write mode.

sudo mount -w /dev/vdb1 /mnt
umount
Command Introduction
The umount command is used to uninstall a file system.
Common parameter description
parameter
explain
-r
If uninstallation fails, attempt to remount in read-only mode.
-a
Uninstall all file systems described in the/etc/mtab file.
-t
Only uninstall file systems of specified types. If you want to specify multiple file systems at once, you can separate them with commas.
-f
Forced uninstallation.
Example usage
Forcefully uninstall the specified partition.

sudo umount -f /dev/vdb1
management service
systemctl
Command Introduction
The systemctl command is used for service management.
Common parameter description
parameter
explain
-a
List all loaded units or attributes.
Common Unit Commands
command
explain
start
Start the specified loaded unit.
stop
Stop the specified loaded unit.
restart
Restart the specified loaded unit.
reload
Require the specified units to reload their configurations.
status
Display the runtime status information of the specified unit. The common service operation status is shown below.
active (running): The service is running in the background.
active (exited): The service has already run and exited.
active (waiting): The service is running but waiting to be triggered by specific conditions or events.
inactive: The service is currently not running.
Common Unit File Commands
command
explain
enable
Enable the specified unit or unit instance.
disable
Disable the specified unit or unit instance.
Example usage
Restart the nginx service.

sudo systemctl restart nginx
View nginx service status.

sudo systemctl status nginx
Set up nginx service startup.

sudo systemctl enable nginx
Manage resource utilization
lsof
Command Introduction
The lsof command is used to list open files.
explain
If the Linux distribution you are using does not come pre installed with the lsof tool, you can use the corresponding package management tool for installation.
Alibaba Cloud Linux、CentOS、RHEL:sudo yum install lsof。
Ubuntu、Debian:sudo apt install lsof。
Common parameter description
parameter
explain
-p
Output the file opened by the specified process.
-l
Use ID instead of username in output.
-u
Output files opened by the specified user.
-c
Output the items in the AND column that contain the specified keyword.
-d
Output items containing specified descriptors.
-i
Output items that meet the specified criteria. The optional parameters are as follows:
46: Refers to IPv4 IPv6。
protocol: TCP and UDP can be specified.
hostname: Network host name.
Hostaddr: IP address.
service: The name included in/etc/services.
port: The port number can be multiple.
Display information explanation
The example of the echo information after running the lsof command is as follows:
image
The relevant parameters are explained as follows.
parameter
explain
COMMAND
Command name.
PID
Process ID.
TID
Thread ID, if it is empty, it means the process is listed.
TASKCMD
The task name is usually the same as COMMAND.
USER
User ID number or login name.
FD
File descriptor.
TYPE
The type of node associated with the file.
DEVICE
Equipment number.
SIZE/OFF
File size/offset, in bytes.
NODE
File nodes.
NAME
The file mount point and the system where the file is located.
Example usage
List the files opened by the specified process

sudo lsof -p 1
Please replace the PID of process 1 in the above command with the process PID you specified.
View files opened by processes related to the specified user

sudo lsof -u <user-name>
Please replace the<user name>in the above command with the Linux system username you specified.
View process information related to opening the specified file

sudo lsof <file-name>
Please replace the<file name>in the above command with the file name you specified.
Output all items with IPv4 TYPE

sudo lsof -i 4
netstat
Command Introduction
The Netstat command is used to display TCP, UDP ports, processes, and other related information.
Common parameter description
parameter
explain
-t
Only display TCP related options.
-u
Only display UDP related options.
-i
Display the list of network cards.
-n
Refuse to display aliases, convert all numbers that can be displayed to numbers.
-l
Only list the service status in Listen.
-p
Display the program name that established the relevant link.
-s
Display network statistics information.
Example usage
Check the occupancy status of port 8000.

netstat -tunlp | grep 8000
Please replace the 8000 port in the above command with the process PID you specified.
View the usage of all TCP ports.

netstat -ntlp

  • Linux系统常用命令, Linux, linux os, Common commands for Linux server systems
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to change the root user password of Linux operating system

Changing the root user password of the Linux operating system is a critical operation, please...

Can websites not use SSL certificates? There may be issues with websites not installing SSL certificates

Website security certificate, also known as website SSL certificate. Nowadays, we see many...

Several of the most common encryption and decryption methods

Encryption and decryption are the most commonly used data conversion methods in communication....

Method for modifying server hostname in Linux system

How to modify the hostname in LinuxHow to modify the Linux hostname? You can temporarily modify...

Call WordPress to customize the content of article categories

If we have a custom WordPress article classification, how can we operate it separately if...