LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

printf

Format and print data with specifiers

TLDR

Print formatted output
$ printf "%s\n" "Hello"
copy
Print with variables
$ printf "Name: %s, Age: %d\n" "[name]" [25]
copy
Print hexadecimal
$ printf "%x\n" [255]
copy
Print with padding
$ printf "%10s\n" "text"
copy
Print floating point
$ printf "%.2f\n" [3.14159]
copy

SYNOPSIS

printf format [arguments]

DESCRIPTION

printf formats and prints data according to a format string, similar to the C library function of the same name. The format string can contain literal text, escape sequences like \n and \t, and conversion specifiers such as %s for strings, %d for integers, %f for floating-point numbers, and %x for hexadecimal.Unlike echo, printf provides precise control over output formatting and behaves consistently across shells and platforms. If more arguments are provided than the format string consumes, the format string is reused, making it easy to process lists. The command does not append a trailing newline unless explicitly included with \n in the format string.printf is part of GNU coreutils and is also available as a shell built-in in most shells. It is the preferred tool for generating formatted output in portable shell scripts.

PARAMETERS

FORMAT

Format string.
ARGUMENTS
Values to format.
%s
String.
%d
Integer.
%f
Float.
%x
Hexadecimal.
%o
Octal.

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

Format string required. More portable than echo.

HISTORY

printf originated from C programming language formatting functions.

SEE ALSO

echo(1), print(1), fmt(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid