To what that is, run help :
in the shell. It gives:
$ help :
:: :
Null command.
No effect; the command does nothing.
Exit Status:
Always succeeds.
Very useful in one-liner infinite loops, for example:
while :; do date; sleep 1; done
Again, you could write the same thing with true
instead of :
, but this is shorter.
Interestingly:
$ help true
true: true
Return a successful result.
Exit Status:
Always succeeds.
According to this, the difference is that :
is "Null command",
while true
is "Returns a successful result".
Another difference is that true
is usually a real binary:
$ which true
/usr/bin/true
On the other hand, which :
gives nothing. (Which makes sense, being a "null command".)
Anyway, @Andy is right, this is duplicate of this other post, which explains it much better.