printf '%05d\n' 42

Category: Administration

printf '%05d\n' 42

Format a number with zero padding

printf is the shell's formatted output builtin, and %05d pads the number 42 to five digits with leading zeros, printing 00042. The same format specifiers as C and Python apply, so %x gives hex and %.2f fixes decimals. It is more predictable than echo for scripted output.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.