I have a few very simple bash scripts that I cobbled together for things that I do regularly. One of them is to run duplicity to do my backup tasks. Nothing clever just a bunch of if .. then statements really. As this needs to be run as sudo would it be best practice to put my script in /usr/bin ( or other location in PATH ) , chown to root.root and chmod to 700 ?
I save my own scripts in
If your script should executeable by every system user, you can create a symbolic link to
If only root should execute the script, you can create a symbolic link to
Command to add a symbolic link in
ln -s /opt/scripts/<script> /usr/bin/
You can execute the script, because
/usr/bin/ is in your PATH by default.
If no other users other than you uses these scripts:
Then you can keep them in
/home/$USER/bin. Create the
bin folder if it is not there and move the files there. The bin folder in your home will automatically get added to the PATH environment variable. The code is in the
# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi
Or in some systems it may be in
Thanks Elder Geek
If these script are to be used by other users:
/opt/bin are good options. See Is there a standard place for placing custom Linux scripts?
Hope this helps
I have a directory that I use for the quick collection of my local tools or things that I deploy on various computers in
/usr/local/apollo. There are branches off this directory for
For the applications that I download and install outside of the default
apt-get repositories are placed in
/opt/ and a directory by the app's name, with one more sub-directory for the specific version of the application. This way my compiled version of an application like
eclipse won't conflict with the distributed version.
My use of
/opt is the way it's basically officially designed.
By the way the directories
/opt survives a fresh OS version installation overwrite.