Print the associated argument while interpreting backslash escapes in there
%q
Print the associated argument shell-quoted, reusable as input
%d
Print the associated argument as signed decimal number
%i
Same as %d
%o
Print the associated argument as unsigned octal number
%u
Print the associated argument as unsigned decimal number
%x
Print the associated argument as unsigned hexadecimal number with lower-case hex-digits (a-f)
%X
Same as %x, but with upper-case hex-digits (A-F)
%f
Interpret and print the associated argument as floating point number
%e
Interpret the associated argument as double, and print it in ±e format
%E
Same as %e, but with an upper-case E in the printed format
%g
Interprets the associated argument as double, but prints it like %f or %e
%G
Same as %g, but print it like %E
%c
Interprets the associated argument as character: only the first character of a given argument is printed
%s
Interprets the associated argument literally as string
%b
Interprets the associated argument as a string and interpreting escape sequences in it
%q
Prints the associated argument in a format, that it can be re-used as shell-input (escaped spaces etc..)
%n
No conversion or printing is done. Assigns the number of so far printed characters to the variable named in the corresponding argument (similat to C's printf)
%(FORMAT)T
output the date-time string resulting from using FORMAT as a format string for strftime(3). The associated argument is the number of seconds since Epoch, or -1 (current time) or -2 (shell startup time)
%%
No conversion is done. Produces a % (percent sign)
Any number: Specifies a minimum field width, if the text to print is smaller, it's padded with spaces, if the text is bigger, the field is expanded
.
The dot: Together with a field width, the field is not expanded when the text is bigger, the text is cutted instead. "%.s" is an undocumented equivalent for "%.0s", which will force a field width of zero, effectively hiding the field from output
*
The asterisk: the width is given as argument before the string or number. Usage (the "*" corresponds to the "20"): printf "%*s\n" 20 "test string"
#
"Alternative format" for numbers: see table below
-
Left-bound text printing in the field (standard is right-bound)
0
Pads numbers with zeros, not spaces
Pad a positive number with a space, where a minus (-) is for negative numbers
+
Prints all numbers signed (+ for positive, - for negative)
Alternative Format
%#o
The octal number is printed with a leading zero, unless it's zero itself
%#x, %#X
The hex number is printed with a leading "0x"/"0X", unless it's zero
%#g, %#G
The float number is printed with trailing zeros until the number of digits for the current precision is reached (usually trailing zeros are not printed)
all number formats except %d, %o, %x, %X
Always print a decimal point in the output, even if no digits follow it