Text Processing

printf

Format and print data with C-style format strings for precise output control.

Synopsis

syntax
printf FORMAT [ARGUMENT]...

Examples

Print each argument on its own line
printf '%s\n' 'hello' 'world'
Formatted table output
printf '%-20s %5d\n' 'Alice' 42 'Bob' 37
Print number in hexadecimal
printf '%x\n' 255
Print float with 2 decimal places
printf '%.2f\n' 3.14159

About printf

The `printf` command format and print data with C-style format strings for precise output control. Text processing commands transform, format, and generate text output.

Linux's philosophy of small composable tools shines here — these commands are designed to be piped together to build complex text-processing workflows. They are indispensable for scripting, log analysis, and data transformation tasks.

The command accepts 0 commonly used flags shown above, though the full set of options is available in the man page (`man printf`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More Text Processing Commands

Other commands in the Text Processing category

Related tools