Intro To 'false' Command In Linux
2023-05-21 - By Robert Elder
I use the 'false' command which does absolutely nothing and then exits unsuccessfully:
The 'false' command can be built into the shell or it can exist as a regular executable:
type -a false
false is a shell builtin false is /usr/bin/false false is /bin/false
Return Code 1 == 'Failure'
Whenever you run the 'false' command, it will exit with an unsuccessful return code:
You can verify this by echoing the dollar sign question mark variable and then observing the value of 1 which indicates an unsuccessful program exit:
Use Case Of 'false' Command
An example application of the 'false' command is to deny certain users the ability to access a shell environment.
For example, on my machine the postgres user is configured to spawn the '/bin/bash' shell environment upon login:
cat /etc/passwd | grep postgres
Whenever I use sudo to become the 'postgres' user:
sudo -u postgres -i
this will work normally and run the '/bin/bash' shell as indicated in '/etc/passwd'.
However, the 'tomcat' user is configured to launch the 'false' command as its login shell:
cat /etc/passwd | grep tomcat
This fails immediately and prevents access to any form of login shell:
sudo -u tomcat -i
This is because the 'false' command simply exits immediately with an error code.
And that's why the 'false' command is my favourite Linux command.
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
The Most Confusing Grep Mistakes I've Ever Made
Use The 'tail' Command To Monitor Everything
Using A Piece Of Paper As A Display Terminal - ed Vs. vim
An Introduction To Data Science On The Linux Command Line
An Overview of How to Do Everything with Raspberry Pi Cameras
Why Bother Subscribing?