LinuxCommandLibrary

hr

Draw horizontal rule in the terminal

TLDR

Print a horizontal rule

$ hr
copy

Print a horizontal rule with a custom string
$ hr [string]
copy

Print a multiline horizontal rule
$ hr [string1 string2 ...]
copy

SYNOPSIS

hr [CHAR]

PARAMETERS

[CHAR]
    Optional single character to repeat across the terminal width (default: -)

DESCRIPTION

The hr command is a simple, lightweight Unix utility that outputs a horizontal rule spanning the full width of the terminal window. Ideal for visually separating sections in shell scripts, logs, or interactive sessions, it repeats a specified character (or default hyphen -) to create clean dividers.

It detects terminal width via the $COLUMNS environment variable or tput cols, ensuring adaptability to window resizes. Following Unix philosophy, hr is minimalistic—no flags, no dependencies beyond basic shell tools—making it perfect for dotfiles and ricing setups.

Common uses include script output formatting, menu separators, or progress indicators. Though not in coreutils, it's easily sourced from GitHub or packaged in some distros, embodying efficient terminal aesthetics.

CAVEATS

Depends on $COLUMNS or tput for width detection; fails in non-terminals or if both unavailable. Not a standard command—install manually. Handles only single chars reliably; multi-char strings may truncate unevenly.

EXAMPLES

hr
───────... (hyphens fill screen)

hr =
══════... (equals fill screen)

hr '█'
████████████████... (blocks fill screen)

SOURCE IMPLEMENTATION

Typical script:
#!/bin/sh
[ -z "$1" ] && c='-' || c="$1"
printf '%*s ' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "$c"

HISTORY

Created circa 2018 by Luke Smith for his voidrice GitHub dotfiles repo. Popularized in suckless.org, Larry McVoy (9front), and minimalist Linux communities for its brevity (often a 2-line shell script). Now packaged in some distros like Artix Linux.

SEE ALSO

tput(1), printf(1)

Copied to clipboard