Where can (should) I put my (bash) script so that it can be used (forever) by terminal or by a direct command: Alt+F2?
I know there is /usr/bin
and /sbin
& /bin
directories but when should I use between them?
Where should I put my script?
Where can (should) I put my (bash) script so that it can be used (forever) by terminal or by a direct command: Alt+F2?
I know there is /usr/bin
and /sbin
& /bin
directories but when should I use between them?
Where should I put my script?
It depends on who will use your script:
$HOME/.local/bin
(As per the XDG Base Directory Specification)/usr/local/bin
root
only - /usr/local/sbin
That way you have your own scripts separated from the distribution-provided binaries.
.../sbin
directories are used for statically-linked binaries (mostly used by root
, before shared libraries are available), not user scripts.
May 13, 2014 at 12:12
~/.local/bin
? (which is already in the PATH
in a couple distributions)
Don't use these directories:
/usr/bin
,/sbin
and/bin
Leave them for package-managed executables.
If you need the script for one user, waltinator's answer is fine.
If you need the script for all users on your system (but you can also use this for one user), stick it in /usr/local/bin/
. One advantage: this directory is already in your PATH so there is no need to edit files.
.sh
file? Take a hello-world.sh
file for example.
Mar 10, 2020 at 12:42
#!/bin/sh
at the first line, chmod
it +x
and put it in /usr/local/bin/
. The extension is not needed. when you run it it will execute your script with /bin/sh
. You can also put /bin/node
there for a javascript file.
You should put your script under $HOME/bin
. Follow below PATH to achieve this:
mkdir $HOME/bin
Then put your script in $HOME/bin
Finally, add the following line under $HOME/.bashrc
by editing with gedit $HOME/.bashrc
export PATH="$HOME/bin:$PATH"
When the system is looking for the command you typed, it will look in each directory of $PATH
and execute the first match it finds.
~/.profile
. ;)
May 13, 2014 at 6:24
~/.local/bin
is already in the PATH
. Any reason against using it for personal scripts?