If you're new to the Linux world, you may be surprised to know that you can view and manage almost all system resources using simple terminal commands. Instead of having to open various settings pages and control panel dialog boxes, you can simply type in a command and view the output. Here is how you can manage how your Linux system uses the resources available on your machine using such commands.

1. View all running processes at a glance

Linux allows you to easily view all running processes using the top command, which Windows users may find similar to the Task Manager.

Open the terminal and type top and you will see how much CPU, RAM, and other resources are being used and these will be updated in real-time.

2. A more user-friendly approach to viewing running processes

htop is a more colorful and user-friendly version and is pre-installed with many Linux distros. Compared to the standard top command, htop is much more colorful, with the resource usage appearing at the top of the screen as bars. You can also adjust how you want to view the resource usage, such as sorting by CPU usage or memory.

If htop is installed on your system, you simply type it in the terminal to run it. If it isn't, you can use the sudo apt install htop to install it on Ubuntu and Debian systems.

3. Check network traffic for a program or service

You can use the tcpdump command to check the network traffic for a particular program or service as well as to debug network problems.

The tcpdump command provides information like the number of bytes transferred, protocol type in use, destination IP, source IP, etc. It can help you detect abnormal network activity or trace a network call.

The command can be especially useful if a service or package is making calls to IP addresses or hosts that are unauthorized, and to find whether any packages are being downloaded or sensitive data is being shared leading to potential security risks.

netstat is another command that you can use to view network-related information, such as the status of your network connection, connections to other IP addresses, open ports, protocol in use, foreign and local IP addresses, etc.

You can use it to determine whether a process is keeping all its ports open and whether they are being used or not, which can help sort out network-related problems. It can help you ensure that no unnecessary ports are open that can create security vulnerabilities.

5. Check the amount of free memory in your system

To check the amount of free memory your machine has, you can use the free command in the terminal.

This command shows the physical RAM installed in your machine as well as its virtual memory or swap space. The command shows the amount of free memory in blocks when you run it without any argument.

However, if you want to view the free memory in megabytes or gigabytes, you will have to use the -f option, so the final command will be free -h.

6. Monitor all I/O activity on your system

In Linux, all actions take place through files, which are written to connected disks. When you run a process, it also uses disk bandwidth along with memory and CPU. This means that every process performs certain I/O (input/output) operations and this is also limited like other resources such as RAM and CPU.

The iostat command lets you monitor I/O activity as well as how much CPU is being used by a particular process.

7. View available virtual memory

Like other operating systems, Linux can use virtual memory to store processes for operations that are not currently running and don't need to be in the RAM. This lets the system use more memory than is available physically, though the virtual memory is slower. The kernel can swap processes in and out as required since Linux distros create a swap partition when you log in.

You can use the vmstat command to view the amount of virtual RAM being used if you feel your system is getting slow. The command shows the amount of memory being used as swap, how much memory is free, the amount of memory used as cache, and the amount used in buffers. This information can be especially useful for system programmers and can also help identify and fix performance problems.

Note: The top and htop commands also show swap and physical memory.

8. Monitor I/O usage in real time

The iotop command lets you monitor disk input/output usage in real time. It provides information such as the total disk available, disk read, total disk to write and the amount actually written.

It lets you view all threads that are performing I/O operations, providing detailed information like the thread owner (user), thread priority, bandwidth being used, etc.

Like many other commands, you can modify the iotop command to filter threads and only show those performing I/O operations, using iotop -o or iotop --only.

9. Check your disk space

In Linux, you can check the amount of disk space available using the du and df commands.

The du command shows you the sizes of the files in a specific directory. You can type in the directory address after the command for that purpose, such as du /usr/local/bin.

The df command shows you the available space on all storage drives mounted on the system. To see the amount of storage free on a drive, you will need to run the command with a path as an argument.

For instance, to check the free storage on the root directory, the command will be df /.

Again for both the du and df commands, you will need to use the -h command to view the storage in a human-readable format, like megabytes or gigabytes.

10. Monitor multi-processor usage

If you want to check how various processors on your system are being used, you can use the mpstat command. This command shows detailed CPU utilization data along with how each processor is performing, making it a handy tool for performance analysts, developers, and system administrators.

mpstat can show you statistics for each individual processor core. You can run the command and add a time interval to view the CPU usage for different processors like mpstat -P ALL 5.

11. View open files

If a file is being used by the system, you won't be able to log out. To view the file in question, you can use the Isof command. This will show you all files that are currently open as well as all devices since they are also treated as files in the Linux system. Once you find the file that is preventing you from logging out, you can close it or kill the process using it.

Additionally, the Isof command shows network sockets which can help you check whether there are any unauthorized connections to your system. The most important things you need to pay attention to include the command name and the complete pathname of the file that is open. These are present under the 'COMMAND' and 'NAME' fields.

12. Monitor your overall system performance and usage

The nmon command is a fully interactive command that lets you monitor your Linux system performance. It shows information about various resources, top processes, file systems, disks, networks, memory, and CPU.

Since it is an interactive command, you can view different types of information without running multiple commands.

For instance, if you want to view the CPU performance, press the c key on your keyboard, while pressing the t key shows the top processes currently running.

13. Check how long your machine has been running

You can find out how long your machine has been running using the uptime command. This command shows the time for which the machine has been running since it was booted up last, the number of users currently logged in, the load averages for different intervals, and the current time.

If you want to see the time when the system was booted on by itself, use the -s command.

Things to know

  • These are just some of the commands that you can use to view and manage your Linux system effectively, but there are many more that can make this task easier.
  • In Linux, you can run commands with the sudo prefix, which grants you root privileges, but doing so can be quite risky. Running commands using sudo without proper knowledge can break your system and make it unusable.
  • While you can find GUI-based controls to perform many of the actions that these commands perform, this may not always be the case. Also, in certain situations, running the commands is much simpler and faster.