true

Linux · Terminal · reference only

What it does

Does nothing and always exits with status 0, which means success. It is used in infinite loops and to force a success.

Syntax

true

Options and parameters

  • (sin argumentos)

    Always returns exit status 0.

  • --help

    Shows help (only in the external /usr/bin/true version).

  • --version

    Shows the version (only in the external /usr/bin/true version).

Usage examples

  • true; echo $?

    Prints 0, true's exit status.

  • while true; do date; sleep 1; done

    Infinite loop that prints the time every second; stop it with Ctrl+C.

  • rm fichero_que_quizas_no_existe || true

    Keeps an rm error from making a script with set -e fail.

  • true && echo "ok"

    Since true always succeeds, the second command runs.

Notes and common mistakes

  • Its opposite is false, which always returns 1.
  • In bash it is a builtin, so it does not create a new process.

Related commands