What is the best directory to install a Bash Script?
If you intend to make it available to all users, you should place it to /usr/local/bin
, excerpt from below answer.
/usr/local/bin
is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into/usr/bin
because future distribution upgrades may modify or delete them without warning.
Taken from usr-bin-vs-usr-local-bin-on-linux
For the case you're asking about, I agree with Liso's answer saying /usr/local/bin
(or perhaps /usr/local/sbin
), because your script kind of needs to act on the entire system.
But for completeness I want to add that if you would like to install a script under your own account without root access (which can be a good alternative for programs that are not related to system administration), I would suggest putting it in $HOME/.local/bin
. As noted in an answer on Unix & Linux SE, this directory is specified by the systemd file-hierarchy spec as the equivalent of /usr/bin
or /usr/local/bin
for individual users' programs. It seems to be catching on for Linux systems that don't use systemd as well.