Random GNU/Linux commands

Tasha is studying to become a RHEL Sysadmin. Pick a random GNU/Linux command, and give her several examples of how to use it correctly on a modern RHEL server.

Command: systemctl

The systemctl command is a powerful tool for managing services and systemd units on modern RHEL servers. It offers a variety of options and subcommands for controlling the state of services, daemons, and other system components.

Here are several examples of how Tasha can use the systemctl command on a modern RHEL server:

1. Start/Stop a Service:

  • Start the httpd service: sudo systemctl start httpd
  • Stop the sshd service: sudo systemctl stop sshd

2. Check the Status of a Service:

  • Check if the mariadb service is running: sudo systemctl status mariadb
  • Determine the last time the crond service ran: sudo systemctl status crond --no-pager

3. Enable/Disable a Service:

  • Enable the postfix service to start automatically during boot: sudo systemctl enable postfix
  • Disable the bluetooth service to prevent it from running: sudo systemctl disable bluetooth

4. Manage Systemd Units:

  • List all systemd units: sudo systemctl list-units
  • Check the configuration of the network.service unit: sudo systemctl cat network.service
  • Reload the configuration of all systemd units: sudo systemctl daemon-reload

5. Control System Power:

  • Reboot the system: sudo systemctl reboot
  • Power off the system: sudo systemctl poweroff

6. Use Timers with Services:

  • Schedule the backup.service to run every day at 2:00 AM: sudo systemctl set-timer 'backup.timer' 'OnCalendar=daily 02:00'
  • Check the remaining time until the next run of the cleanup.timersudo systemctl show-activation cleanup.timer

7. Utilize systemctl with Conditions:

  • Start the firewalld service only if the network interface is active: sudo systemctl start firewalld --condition=network-online
  • Stop the ntp service when the system is running on battery power: sudo systemctl stop ntp --condition=PowerSupply=Battery

8. Combine systemctl with other commands:

  • Use systemctl with pipes to filter output: sudo systemctl list-units --no-pager | grep httpd
  • Combine systemctl with xargs to perform actions on multiple services: sudo systemctl stop $(systemctl list-units --type=service --state=running | grep http)

These are just a few examples of how Tasha can use the systemctl command on a modern RHEL server. As she continues to learn and explore, she will discover even more ways to leverage this powerful tool for efficient system management.

You should also read: