Text and processing

The printf command

Prints formatted text. Unlike echo, it reliably interprets sequences such as \n (newline) or \t (tab).

Syntax

printf 'formato' [argumentos]

Copy-ready examples

$ printf 'hola\n'Print with a newline
$ printf 'a\tb\n'Print with a tab

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • printf does not add a newline on its own: you must include \n if you want one.

Related commands

FAQ

Why use printf instead of echo?

Because printf is predictable with newlines and tabs in any shell.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course