Aligned Output With printf
Format columns and numbers precisely from a shell script.
Run printf "%-10s %5d\n" name 42 to print a left-aligned string and right-aligned number.
01Command
Command
$ printf "%-10s %5d\n" name 4202What it does
printf gives scripts the same formatting vocabulary as C, so reports and tables can be generated without a templating language. It also avoids the portability and quoting traps of echo, making script output predictable.
03Risk
!Warning: The format string is reused for extra arguments; ensure the count matches or intentionally loop.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- printf.1.en.html manual pageEvidence: Documents the printf command and format syntax.
Last verified: 2026-10-13 · Category: Developer