![Forrest logo](/images/logo.png)
hostnamectl:tldr:e755d
This command is used to set the hostname of a Linux system using the hostnamectl
command with sudo
privileges.
Let's break down the command:
-
sudo
: This is a command used in Unix-like systems to execute a command with administrative/root privileges. It allows the user to run a command as another user, usually the superuser. -
hostnamectl
: This is a command-line tool used in Linux systems to control and set the system's hostname. -
set-hostname
: This option, when used withhostnamectl
, allows us to set or change the hostname of the system. -
--static "${hostname-example-com}"
: This part of the command sets the static hostname of the system to the value of the variablehostname-example-com
. The double quotes are used to make sure the value is interpreted as a single string. You would replace${hostname-example-com}
with the desired hostname, such asexample-com
. -
&&
: This is a command separator in Linux, used to execute the next command only if the previous command succeeds. -
sudo hostnamectl set-hostname --pretty "${hostname}"
: This part of the command sets the pretty hostname of the system to the value of the variablehostname
. The double quotes are used to ensure the value is interpreted as a single string. You would replace${hostname}
with the desired hostname.
In summary, this command sets the static hostname and the pretty hostname of a Linux system using the hostnamectl
command with administrative privileges (sudo
). The static hostname is a persistent name that doesn't change across reboots, while the pretty hostname is a more human-readable variant.