In this article, We will discuss the most useful Linux system resource commands with real-time examples.
Important Commands:
df
du
free
systemctl list-unit-files
service
ps
kill
top
htop
hostname
ifconfig
last
w
tee
df
The df
command in Linux is used to display information about disk space usage on file systems.
master@master:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 393M 2.3M 390M 1% /run
/dev/loop3 44M 44M 0 100% /snap/snapd/18600
/dev/loop4 60M 60M 0 100% /snap/core20/1856
/dev/loop5 50M 50M 0 100% /snap/core18/2724
/dev/loop6 92M 92M 0 100% /snap/lxd/24065
/dev/loop0 50M 50M 0 100% /snap/core18/2749
du
The du
command in Linux is used to estimate file and directory disk usage. It provides information about the space consumed by files and directories, including the total size and sizes of individual files or directories.
master@master:~$ du -sh workspace/ #s - summarize
26M workspace/
free
The free
command in Linux is used to display information about system memory usage, including both physical and swap memory. It provides details about the total amount of free, used, and available memory, as well as buffers and cached memory.
master@master:~$ free -h
total used free shared buff/cache available
Mem: 3.8Gi 749Mi 402Mi 2.0Mi 2.7Gi 2.9Gi
Swap: 0B 0B 0B
master@master:~$
systemctl list-unit-files
The systemctl list-unit-files
command in Linux is used to display a list of unit files and their states.
master@master:~$ systemctl list-unit-files --type=service --state=enabled
UNIT FILE STATE VENDOR PRESET
containerd.service enabled enabled
cron.service enabled enabled
docker.service enabled enabled
service
In Linux, the service
command is used to manage system services. It provides a convenient way to start, stop, restart, enable, disable, and check the status of services on a Linux system.
master@master:~$ service docker status
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-05-16 18:40:35 UTC; 3s ago
master@master:~$ service docker stop
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'docker.service'.
Authenticating as: master
Password:
==== AUTHENTICATION COMPLETE ===
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
master@master:~$ service docker start
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'docker.service'.
Authenticating as: master
Password:
==== AUTHENTICATION COMPLETE ===
ps
The ps
command in Linux is used to provide information about currently running processes on the system. It displays a snapshot of the active processes, their process IDs (PIDs), resource utilization, and other details.
master@master:~$ ps -ef | grep -i docker # f -> fill:including pid e -> everyone: all users
root 328179 1 0 18:40 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
master 329302 323019 0 18:44 pts/2 00:00:00 grep --color=auto -i docker
master@master:~$
kill
The kill
command in Linux is used to send signals to processes, allowing you to control their behavior and manage them. It is primarily used to terminate or stop processes gracefully.
master@master:~$ sudo kill -9 4417
stopped containerd
top
The top
command in Linux is a powerful utility for real-time monitoring of system resources. It provides a dynamic view of system processes, CPU usage, memory usage, and other important system statistics.
htop
htop
is an interactive process viewer and system monitor for Linux systems. It provides an enhanced and more user-friendly alternative to the traditional top
command. htop
displays a real-time overview of system processes, their resource utilization, and other system information in a more visually appealing and interactive manner.
hostname
The hostname
command is used to display or set the hostname of a computer. The hostname is a unique name assigned to a device on a network. It helps identify and differentiate devices in a networked environment.
master@master:~$ hostname
master
master@master:~$
ifconfig
This will display the configuration of all active network interfaces on your Ubuntu system. The output will include information such as the IP address, netmask, MAC address, and other network-related parameters for each interface.
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.137.137 netmask 255.255.255.0 broadcast 172.16.137.25
last
The last
command is used to display a list of recent logins and logouts on a Unix-like system. It shows a historical record of user logins and system shutdowns/reboots.
master@master:~$ last
master tty1 Fri Mar 31 15:40 gone - no logout
reboot system boot 5.4.0-146-generi Fri Mar 31 15:40 still running
master tty1 Fri Mar 31 14:45 - down (00:54)
reboot system boot 5.4.0-146-generi Fri Mar 31 14:44 - 15:40 (00:55)
wtmp begins Fri Mar 31 14:44:41 2023
w
The w
command is a command-line utility in Linux and Unix-like systems that provides information about currently logged-in users and their activities. It displays a summary of the system's status, including information about the current time, how long the system has been running, and the number of logged-in users.
master@master:~$ w
16:58:26 up 17:17, 3 users, load average: 0.72, 0.32, 0.25
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
master tty1 - 31Mar23 3days 0.10s 0.10s -bash
master pts/1 172.16. Tue17 46:46m 0.55s 0.05s sshd: master [priv]
master pts/2 172.16 Tue18 0.00s 0.31s 0.01s w
tee
The tee
command is a command-line utility in Linux and Unix-like systems that reads input from standard input (stdin) and writes it to both standard output (stdout) and one or more specified files. It is useful for redirecting and duplicating the output of a command.
master@master:~$ uptime | tee uptime_record.txt
16:59:55 up 17:18, 3 users, load average: 0.23, 0.25, 0.23
master@master:~$ cat uptime_record.txt
16:59:55 up 17:18, 3 users, load average: 0.23, 0.25, 0.23
master@master:~$
End.
Please provide your valuable feedback.