Rocky Linux Core Commands: Page 10

This page covers critical commands for administrative tasks, package management, and system service control.


46. sudo - Execute a Command as Another User

Purpose: The sudo command (substitute user do) allows a permitted user to execute a command as the superuser (root) or another user, as specified by the security policy. It's the primary way to perform administrative tasks without logging in as root directly.

Syntax: sudo COMMAND [ARGUMENTS]

Key Concept:

Examples:

sudo dnf update       # Update system packages
sudo systemctl restart nginx # Restart the Nginx web server
sudo nano /etc/hosts  # Edit system configuration files

47. dnf - DNF Package Manager

Purpose: dnf (Dandified YUM) is the next-generation package manager for RPM-based distributions like Rocky Linux. It's used for installing, updating, removing, and managing software packages.

Syntax (Common Usage): sudo dnf COMMAND [PACKAGE_NAME...]

Key Commands:

Examples:

sudo dnf install httpd
sudo dnf update
sudo dnf remove telnet
dnf search "web server"

48. systemctl - Control the Systemd System and Service Manager

Purpose: The systemctl command is the primary tool for controlling and managing the systemd init system. It's used to manage services, check system status, and interact with the systemd journal.

Syntax (Common Usage): sudo systemctl COMMAND UNIT

Key Commands:

Examples:

sudo systemctl start sshd
sudo systemctl status firewalld
sudo systemctl enable nginx
systemctl is-active mariadb

49. hostname - Show or Set the System's Hostname

Purpose: The hostname command is used to display or set the system's hostname.

Syntax: hostname [OPTIONS] [NEW_HOSTNAME]

Key Options:

Examples:

hostname
hostname -f
sudo hostname new_server_name # Temporarily set hostname (resets on reboot)

To permanently change the hostname, use hostnamectl set-hostname NEW_HOSTNAME (requires root/sudo).


50. history - Display Command History

Purpose: The history command displays a list of commands previously executed in the current shell session and typically previous sessions (stored in ~/.bash_history or similar).

Syntax: history [OPTIONS]

Key Uses:

Examples:

history
history 10
!456       # Execute command number 456 from history
!sudo      # Execute the last command that started with 'sudo'