Linux command
true 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Return success
true
Use in infinite loop
while true; do [command]; sleep [1]; done
Use in conditional
if true; then echo "always runs"; fi
Ignore command failure
command || true
As no-op command
true; echo "continues regardless"
说明
true does nothing except return an exit status of 0 (success). Any arguments provided are ignored. The command is used in shell scripts where a command is syntactically required but no action is needed. Common uses include: - Infinite loops: while true; do ...; done - Ignoring failures: command || true (prevents script exit with set -e) - Placeholder in conditionals when logic is still being developed - Initializing variables with command substitution that must succeed As a shell builtin in most shells, true executes without spawning a subprocess, making it efficient for frequent use in loops.
FAQ
What is the true command used for?
true does nothing except return an exit status of 0 (success). Any arguments provided are ignored. The command is used in shell scripts where a command is syntactically required but no action is needed. Common uses include: - Infinite loops: while true; do ...; done - Ignoring failures: command || true (prevents script exit with set -e) - Placeholder in conditionals when logic is still being developed - Initializing variables with command substitution that must succeed As a shell builtin in most shells, true executes without spawning a subprocess, making it efficient for frequent use in loops.
How do I run a basic true example?
Run `true` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
Where can I find more true examples?
This page includes 5 examples for true, plus related commands for nearby Linux tasks.