Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Monitoring system resources is a critical task for ensuring the smooth operation of Linux systems. This article will guide you through various command-line tools available in Linux to monitor CPU, memory, disk usage, and network activity.
Monitoring CPU Usage with top
and htop
:
The top
command provides a real-time view of the system's CPU usage, memory usage, and running processes.
top
For a more user-friendly interface, you can use htop
, which is not installed by default on all systems but can be installed via package managers like apt
or yum
.
sudo apt-get install htop # For Debian-based systems
sudo yum install htop # For Red Hat-based systems
htop
Checking Memory Usage with free
:
The free
command displays the total amount of free and used physical and swap memory in the system.
free -h
The -h
option provides the output in a human-readable format.
Monitoring Disk Usage with df
and du
:
To check disk space usage, use the df
command:
df -h
The -h
option makes the output human-readable. To see disk usage for specific directories, use the du
command:
du -sh /path/to/directory
Network Activity with iftop
and nload
:
iftop
is a tool that displays bandwidth usage on an interface by host. It is not installed by default but can be installed using:
sudo apt-get install iftop # For Debian-based systems
sudo yum install iftop # For Red Hat-based systems
sudo iftop -i eth0 # Replace eth0 with your network interface
For a simple view of network traffic, nload
can be used:
sudo apt-get install nload # For Debian-based systems
sudo yum install nload # For Red Hat-based systems
nload
Process Monitoring with ps
and kill
:
To view all running processes, use the ps
command:
ps aux
To terminate a process, use the kill
command followed by the process ID (PID):
kill -9 <PID>
System Logs with tail
and journalctl
:
To view the last few lines of a log file, use tail
:
tail -f /var/log/syslog
For systems using systemd
, journalctl
can be used to view logs:
journalctl -xe
By using these tools, you can effectively monitor and manage system resources in a Linux environment, ensuring optimal performance and stability.