hostname(1)

hostname1

Set or print name of current host system

Usage

hostname [-f] [{-s | -d}] [name-of-host]

Overview

The hostname utility prints the name of the current host. The super-user can set the hostname by supplying an argument. To keep the hostname between reboots, run ‘scutil --set HostName name-of-host’.

Options:

-f

Include domain information in the printed name. This is the default behavior.

-s

Trim off any domain information from the printed name.

-d

Only print domain information.

Examples

Set the host name of the machine and check the result:

$ hostname beastie.localdomain.org
$ hostname
beastie.localdomain.org

Do not show domain information:

$ hostname -s
beastie

Show only domain information:

$ hostname -d
localdomain.org

Releases

163 releases since Mac OS X 10.0; the text changed 3 times.

  1. 10.0–10.2.8
  2. 10.3–10.5.8
  3. 10.6–12.2
  4. 12.3–26.5

-d since macOS 12.3; -f since Mac OS X 10.6.

History

The hostname command appeared in 4.2BSD.

From shell_cmds 329 in macOS 26.5. Parsed by carta from the page's mdoc source.