Problem
What is /bin/true on a Linux system? What is the purpose of it?
Asked by Hulk
Solution #1
A command that returns 0 is /bin/true (a truth value in the shell).
Its purpose is to be used in shell scripts when you would ordinarily use a literal like “true” in a programming language, but the shell will only execute a command.
The reverse, /bin/false, returns a non-zero value (a false value in the shell).
Answered by camh
Solution #2
The following is taken from the man page:
true - do nothing, successfully
true returns a status 0.
Answered by user231967
Solution #3
It’s worth noting that it’s not merely amusing or visually appealing. It can be used to quit a program without triggering the end handlers, which can cause problems when multi-threading or forked applications are used. In Perl, for example:
#!/usr/bin/env perl
exec "/bin/true";
END {
print "This wont get printed .. would have if I just 'exit' or 'die'\n";
}
Answered by user3072567
Solution #4
It’s been used to deceive a system into thinking a command has ran when it hasn’t. If a command fails, such as looping, a symlink to ‘true’ can be used to get the master task to start. Only if the position being replaced isn’t critical.
Answered by Sunshine
Solution #5
Simply put, it’s a program that returns 0. This value is sometimes required to make the script more understandable. When you need to utilize a command for a true value, this is the method to employ.
Answered by Marcus Thornton
Post is based on https://stackoverflow.com/questions/2175405/what-is-bin-true