Skip to content

false Command Cheat Sheet

The false command does absolutely nothing, except return an exit status of 1 (failure). It is the opposite of true.


Synopsis

false

Basic Usage

Return Failure

false
echo $?
# Output: 1

Use Cases

Infinite Loops

While true is used for infinite loops (while true; do...), until false can achieve the same, though it's less common.

until false; do
    echo "Running..."
    sleep 1
done

Placeholder for "Code to be written"

Use it to force a fail condition in logic you haven't implemented yet.

if false; then
    echo "This code is unreachable"
fi

Logic Negation

Testing if a command fails using logic operators.

# Run backup only if validation fails
validate_data || backup_corrupted_state
If you want to simulate validation failing:
false || echo "Validation failed, backing up..."


Disabling User Shells

One of the most practical uses of false is in /etc/passwd. By setting a user's shell to /bin/false (or /usr/bin/false), you prevent them from logging in interactively via SSH or console, while still allowing services (like FTP or Mail) to use the account if configured to not require a shell.

ftpuser:x:1001:1001::/home/ftpuser:/bin/false
  • Effect: If ftpuser tries to SSH, the connection closes immediately (because the "shell" runs false and exits).
  • Alternative: /sbin/nologin is often preferred because it prints a polite message ("This account is currently not available") before exiting. false just exits silently.

suppressing Output / Dry Run

In a script where a command variable runs a task, setting that variable to false disables the task effectively.

# Config
ENABLE_UPLOAD=false

# Script
if $ENABLE_UPLOAD; then
    upload_files
else
    echo "Upload disabled"
fi

Creating Failing Unit Tests

In continuous integration (CI) pipelines, false is an easy way to verify that your error handling or failure notifications work.

# Step that is expected to fail
false

Exit Status

Code Meaning
1 Failure (Always)

Notes

  • false ignores all arguments. false --help will simply return exit code 1 (it won't show help).
  • It is often implemented as a shell builtin for speed, but a binary /usr/bin/false also exists.