printf
text processingLinux/Unix
The printf command is one of the most frequently used commands in Linux/Unix-like operating systems. printf Format and print data
Quick Reference
Command Name:
printf
Category:
text processing
Platform:
Linux/Unix
Basic Usage:
printf [options] [arguments]
Common Use Cases
Syntax
printf FORMAT [ARGUMENT]...
Options
Format Specifier | Description |
---|---|
%d, %i |
Print an integer as a signed decimal number |
%u |
Print an integer as an unsigned decimal number |
%f |
Print a floating-point number |
%e, %E |
Print a floating-point number in scientific notation |
%g, %G |
Print a floating-point number in either normal or scientific notation, whichever is more appropriate |
%x, %X |
Print an integer as an unsigned hexadecimal number |
%o |
Print an integer as an unsigned octal number |
%s |
Print a string |
%c |
Print a character |
%% |
Print a literal % character |
\n |
Newline |
\t |
Tab |
\r |
Carriage return |
\\ |
Backslash |
\ooo |
Character with octal value ooo |
\xHH |
Character with hexadecimal value HH |
Examples
How to Use These Examples
The examples below show common ways to use the printf
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
printf "Hello, World!\n"