info > printf

πŸ“„ NAME

printf - format and print data

πŸš€ Quick Reference

Use CaseCommandDescription
Print formatted integerprintf '%d\n' 42Outputs "42" with newline
Print string with escape sequencesprintf 'Hello\nWorld'Prints Hello and World on separate lines
Print Unicode characterprintf '\u20AC\n'Prints Euro currency symbol (€)
Print with precisionprintf '%.2f\n' 3.14159Outputs "3.14"

πŸ“– SYNOPSIS

printf FORMAT [ARGUMENT]...

πŸ“ DESCRIPTION

printf does formatted printing of text. It prints the FORMAT string, interpreting '%' directives and '\' escapes to format numeric and string arguments in a way that is mostly similar to the C printf function. (See printf format directives in libc manual for details.) The differences are listed below.

Due to shell aliases and built-in printf functions, using an unadorned printf interactively or in a script may get you different functionality. Invoke it via env (i.e., env printf ...) to avoid interference from the shell.

printf interprets \OOO in FORMAT as an octal number (1 to 3 digits) specifying a byte, and \xHH as hexadecimal. When \OOO specifies a number >255, the ninth bit is ignored. For example, printf '\400' is equivalent to printf '\0'.

🌟 printf interprets two character syntaxes from ISO C 99: \u for 16-bit Unicode (4 hex digits) and \U for 32-bit Unicode (8 hex digits). It outputs Unicode characters according to LC_CTYPE locale. Ranges U+0000…U+009F, U+D800…U+DFFF cannot be specified except for U+0024 ($), U+0040 (@), and U+0060 (`).

πŸ› οΈ Processing of \u and \U requires a full-featured iconv facility, activated on glibc 2.2+ or with libiconv installed. Otherwise, they print as-is.

Here is how to convert a piece of text into a shell script which will output this text in a locale-independent way:

$ LC_CTYPE=zh_CN.big5 /usr/local/bin/printf \
    '\u4e2d\u6587\n' > sample.txt
$ recode BIG5..JAVA < sample.txt \
    | sed -e "s|^|/usr/local/bin/printf '|" -e "s|$|\\\\n'|" \
    > sample.sh

βš™οΈ OPTIONS

The only options are a lone --help or --version. See Common options. Options must precede operands.

πŸ’‘ Examples

🌍 Unicode Examples

For example, a string containing the Euro currency symbol:

$ env printf '\u20AC 14.95'

will be output correctly in all locales supporting the Euro symbol. Similarly, a Chinese string:

$ env printf '\u4e2d\u6587'

will be output correctly in all Chinese locales.

Note that these examples invoke printf via env to avoid shell aliases or built‑ins.

πŸšͺ Exit Codes

An exit status of 0 indicates success, and a nonzero value indicates failure.

printf
πŸ“„ NAME πŸš€ Quick Reference πŸ“– SYNOPSIS πŸ“ DESCRIPTION βš™οΈ OPTIONS πŸ’‘ Examples
🌍 Unicode Examples
πŸšͺ Exit Codes

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-31 09:02 @216.73.217.152
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^