System administration Linux commands are used to manage and monitor the operating system and its resources.
These commands include:
reboot
"reboot" is a Linux command used to restart the system. It is executed with superuser privileges and it causes the system to go down, restart, and go back up again.
The basic syntax of the command is:
Options available for reboot command include:
- -f or --force: Forces the system to go down and restart immediately, bypassing the normal shutdown procedures.
- -n or --no-sync: Skips the step of writing all unwritten data to disk before rebooting, which can make the reboot faster but may cause data loss.
- -w or --wtmp-only: Only updates the wtmp (login accounting) file, without actually rebooting the system.
- -h or --halt: Halts the system after shutting it down.
Before using the reboot command, it's important to make sure all running processes have been saved and all open files have been closed to prevent data loss.
shutdown
"shutdown" is a Linux command used to shut down or reboot the system.
Usage:
Options:
- -r, --reboot: reboot the system
- -h, --halt: halt the system
- -P, --poweroff: power-off the system
- -H, --halt, --poweroff: halt or power-off the system
- -c, --cancel: cancel a running shutdown
- -k, --kill: don't halt or power off, only send warnings
- -q, --quiet: don't display messages Time:
- +m, --time=minutes: time to wait before shutting down
- -t, --timeout=seconds: time to wait before shutting down
Wall message:
[message] message to be sent to all users
Note: Only the root or a user with the proper permissions can execute this command.init
"init" is the first process started by the kernel when the system boots and is responsible for starting other processes and setting up the system environment. The init process has a process ID (PID) of 1 and is executed by the kernel as the last step of the boot process."init" can take different forms, with the most common being sysvinit, upstart, and systemd. Each form provides a different set of features and management of the boot process and system processes.
"init" is used to:
- Start system services and daemons
- Control the runlevels of the system
- Reap and restart orphaned processes
- Configure the system environment, such as setting up the PATH variable
- Manage system shutdown and reboot.
systemctl
"systemctl" is a system management command in Linux that allows controlling the state of the system and services. It is a front-end for the "systemd" system and service manager.
systemctl can be used to:- Start, stop, restart, reload, or status of a service
- Enable or disable service to start at boot time
- List all services and their status
- Show system status, including system uptime, load average, and logged-in users
- Control the state of the system, including rebooting, shutting down, hibernating, and suspending.
"systemctl" has a variety of options and sub-commands, a few common ones include:
- systemctl start <service> - starts a specified service
- systemctl stop <service> - stops a specified service
- systemctl status <service> - displays the status of a specified service
- systemctl list-units - lists all units and their status
- systemctl is-active <service> - shows if a service is running or inactive
- systemctl enable <service> - enables a specified service to start at boot time.
"systemctl" is a powerful tool that should be used with caution as improper usage can result in system instability.
chkconfig
"chkconfig" is a Linux command-line utility used to manage the system startup scripts in System V-based operating systems such as Red Hat and Fedora. It provides a way to enable or disable specific services from starting during the boot process, and also to manage the levels at which they start (for example, whether a service starts in runlevel 3, runlevel 5, or both).The syntax for using chkconfig is:
For example, to disable the httpd service from starting during the boot process, the command would be:
To check the current runlevel settings for a service, the following command can be used:
The --list option displays the runlevel status for all services, and the runlevel status for a specific service can be displayed by specifying the service name.
service
The service command is a tool to control system services on Linux systems. It provides an interface to manage system services using the init system.
Syntax:
Commands:
- start: starts the specified service
- stop: stops the specified service
- restart: restarts the specified service
- status: displays the status of the specified service
- reload: reloads the configuration of the specified service without restarting it
Note: This command may not be available in all distributions as some have transitioned to using the systemctl command.
top
"top" is a real-time system monitoring tool in Linux that displays system statistics such as CPU usage, and memory usage, and processes information in a dynamic and interactive fashion. By default, it refreshes the display every few seconds, providing an ongoing display of the most resource-intensive processes on the system.
Some common options/flags include:- -d DELAY: Specifies the refresh rate (in seconds) for the display
- -n NUMBER: Specifies the number of iterations (updates) the command should run for
- -p PID: Show statistics for the specified process ID (PID) only
- -u USER: Show statistics for the specified username only
- -h: Displays the help screen for the top.
Example usage:
top (Displays the system statistics)
ps
The ps command is a Linux utility that shows information about the currently running processes and their status. Some of its basic usage and options are:
Display information about the current terminal's processes.
Display information about all processes running on the system, along with their parent process IDs, start time, and CPU usage statistics.
Display information about all processes running on the system, along with the process owner, CPU, memory usage statistics, and process start time.
Display information about all processes running on the system, along with the process ID, parent process ID, CPU usage statistics, and thread information.
ps -p [pid]: Display information about the process with the specified process ID.
The "ps" command is a powerful tool for monitoring the performance and status of processes running on a Linux system. By using the appropriate options, you can filter the output to display only the information that you're interested in.
free
"free" is a Linux command that is used to display the total amount of free and used physical memory and swap space in the system.
Usage:
Options:
- -b, --bytes: Display the amount of memory in bytes.
- -k, --kilo: Display the amount of memory in kilobytes (default).
- -m, --mega: Display the amount of memory in megabytes.
- -g, --giga: Display the amount of memory in gigabytes.
- -h, --human: Display the amount of memory in a human-readable format.
- -c, --count=N: Repeat the display N times.
- -s, --seconds=N: Wait N seconds between each display.
- -t, --total: Show the total sum of memory.
- -V, --version: Show version information.
Example:
The output shows the total memory, used memory, free memory, shared memory, buffer/cache memory, and available memory in the system.
df
display information about disk usage and available space
du
display information about disk space usage of files and directories
uptime
display the system uptime and load average
vmstat
display information about system processes, memory, paging, block I/O, and CPU activity.
iostat
display statistics about input/output operations
lsof
list open files and the processes that have them open
lspci
display information about PCI buses and devices on the system
lsusb
display information about USB buses and devices on the system
systemctl
manage system services and daemons
journalctl
view system logs.