System Commands in Linux
Chapter 4: System Commands in Linux
Overview
In this chapter, we will delve into various system commands in Linux that are essential for managing system processes, resources, and configurations. These commands provide users with insights into system performance and allow for effective system administration.
Key Commands and Examples
top
-u
(user), -p
(PID)
top
top -u username
ps
-e
(all), -f
(full), -u
(user)
ps -ef
`ps aux
kill
-9
(force)
kill PID
kill -9 PID
df
-h
(human-readable)
df -h
df -i
free
-m
(megabytes), -h
(human-readable)
free -m
free -h
uname
-a
(all)
uname -a
uptime
uptime
shutdown
-h
(halt), -r
(reboot)
shutdown -h now
shutdown -r +10
reboot
reboot
Command Descriptions and Use Cases
top
: Displays real-time information about system processes and resource usage.Use Case: Monitoring system performance and identifying resource-hogging processes.
ps
: Shows the current running processes.Use Case: Checking the status of processes or identifying processes by their user or name.
kill
: Terminates a process by its process ID (PID).Use Case: Stopping a misbehaving application or process.
df
: Displays disk space usage for file systems.Use Case: Checking available and used disk space on mounted file systems.
free
: Displays memory usage statistics.Use Case: Monitoring RAM usage and available memory on the system.
uname
: Displays system information.Use Case: Checking kernel version, system architecture, and operating system details.
uptime
: Shows how long the system has been running along with user load averages.Use Case: Determining system stability and performance over time.
shutdown
: Shuts down or reboots the system.Use Case: Safely shutting down the system for maintenance or rebooting for updates.
reboot
: Restarts the system.Use Case: Quickly rebooting the system after applying updates or changes.
Interview Questions and Answers
Q: What does the
top
command do in Linux?A: The
top
command provides a dynamic, real-time view of running processes and their resource usage, allowing users to monitor system performance.
Q: How can you find the PID of a running process?
A: You can find the PID of a running process using the
ps
command, such asps -ef
orps aux
, and then searching for the process name.
Q: What is the difference between
kill
andkill -9
?A: The
kill
command sends a termination signal to a process, whilekill -9
sends a SIGKILL signal that forces the process to terminate immediately without cleanup.
Q: How can you check disk space usage on your system?
A: You can check disk space usage with the
df -h
command, which provides human-readable output of disk usage for all mounted filesystems.
Q: What information does the
free
command provide?A: The
free
command displays information about total, used, free, shared, buffer/cache, and available memory in the system.
Q: What is the purpose of the
shutdown
command?A: The
shutdown
command is used to safely turn off or restart the system, allowing users to perform necessary cleanup and prevent data loss.
Q: How would you check how long the system has been running?
A: You can check how long the system has been running by using the
uptime
command, which displays the current time, how long the system has been up, and the number of users.
Conclusion
This chapter has covered essential system commands in Linux that are critical for managing system processes and resources. Mastery of these commands will enable learners to perform basic system administration tasks efficiently and prepare them for more advanced topics in subsequent chapters.
Last updated