This final chapter covers fundamental commands for user management, managing running processes, and viewing system resource information, all crucial for basic administration and troubleshooting.
1. Running Commands as Superuser (sudo)
The sudo (Substitute User Do) command allows a permitted user to execute a command with the security privileges of another user, usually the root (administrator) user. This is necessary for system-level changes like installing software or modifying core configuration files.
To run a command as root, prepend the command with sudo:
sudo apt update
Note: When you use
sudofor the first time in a new terminal session, the system will prompt you for your own password, not the root user’s password, to verify your identity.
2. Managing Processes
A process is an instance of a running program. Linux provides commands to inspect and manage these processes.
A. Listing Processes (ps)
The ps (process status) command displays information about currently running processes.
To view all processes running on the system in detailed, user-friendly format:
ps aux
a: Shows processes for all users.u: Displays user-oriented format.x: Shows processes not attached to a terminal.
B. Terminating Processes (kill)
The kill command sends a signal to a process, usually to terminate it. It requires the Process ID (PID), which can be found using the ps aux command.
To terminate a process gracefully (soft stop):
kill PID_number
To force a process to terminate immediately (useful for frozen programs), use the -9 (SIGKILL) signal:
kill -9 PID_number
3. Viewing System Resources
System commands help you check available memory and disk space, which is essential for diagnosing performance issues.
A. Checking Disk Space (df)
The df (disk free) command displays the amount of available disk space used by file systems.
To display disk space in a human-readable format:
df -h
B. Checking Memory Usage (free)
The free command displays the total amount of free and used physical and swap memory in the system.
To display memory usage in a human-readable format:
free -h
4. System Shutdown and Reboot
These commands allow you to safely shut down or restart the system. They almost always require sudo.
To reboot the system immediately:
sudo reboot
To shut down the system immediately:
sudo shutdown now
