In Linux systems, there are multiple commands to view the resource usage of the current system. Here are some commonly used commands and instructions:
1. Check memory usage: free
free -h
-h
Parameters are displayed in a human-readable format (such as MB, GB).Output example:
total used free shared buff/cache available Mem: 16Gi 4.2Gi 6.8Gi 238Mi 5.0Gi 11Gi Swap: 2.0Gi 0.0Gi 2.0Gi
2. Check CPU usage: top or htop
top command:
top
-
top
It will display the system's real-time resource usage, including CPU, memory, processes, etc. - according to
q
quittop
。
htop command (need to be installed):
sudo apt install htop # Ubuntu/Debian sudo yum install htop # CentOS/RHEL htop
-
htop
Provides a more friendly interactive interface, allowing you to more easily view CPU and memory usage. - according to
F10
quithtop
。
3. Check disk usage: df
df -h
-
df
Displays the disk space usage of the file system. -
-h
Parameters make the output easier to read (displayed in GB or MB).
Output example:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 100G 50G 45G 55% /
4. Check disk I/O usage: iostat
iostat -x 1
-
iostat
Used to view the system's disk I/O usage. -
-x
Provide more detailed information,1
It means refreshing once every second.
5. Check the process occupancy: ps
ps aux --sort=-%cpu | head -n 10
- Displays the top 10 processes with the highest CPU usage.
-
ps aux
Show all processes,--sort=-%cpu
Sort by descending CPU usage.
6. Check network usage: netstat
netstat -tuln
- Displays all current network connections and port occupancy.
-
-tuln
Parameters indicate the display of TCP connection (-t
), UDP connection (-u
), listen port (-l
), and do not resolve domain names (-n
)。
7. Check the overall usage of system resources: vmstat
vmstat 1
-
vmstat
Displays system memory, paging, process and other information. -
1
It means refreshing once every second.
8. Check the system load: uptime or w
uptime
- Displays the current time of the system, the system running time, the number of logged-in users, and the average load value of the load.
Output example:
08:45:03 up 10 days, 3:21, 3 users, load average: 0.12, 0.22, 0.25
-
load average
Displays the system load of the past 1 minute, 5 minutes, and 15 minutes.
9. View kernel and system information: uname
uname -a
- Displays the kernel version, operating system type, and other information of the system.
10. Check memory and cache usage: slabtop
slabtop
- Displays the memory usage allocated by the kernel, which is usually used to view the kernel cache (slab cache).
Summarize:
- use
free
andtop
Check memory and CPU usage. - use
df
andiostat
Check the disk usage. - use
ps
Check the process occupancy. - use
netstat
Check network connection. - use
vmstat
Check the overall status of the system.
You can choose to use the above commands according to your specific needs to view the system's resource usage.
This is the article about the common commands for Linux to view the current system resource occupancy. For more related content on Linux to view resource occupancy, please search for my previous articles or continue browsing the following related articles. I hope everyone will support me in the future!