Ubuntu – Where should I put the bash scripts

bashscriptssudo

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 ?

Best Answer

I save my own scripts in /opt/scripts.

If your script should executeable by every system user, you can create a symbolic link to /usr/bin.

If only root should execute the script, you can create a symbolic link to /usr/sbin.

Command to add a symbolic link in /usr/bin/:

ln -s /opt/scripts/<script> /usr/bin/

You can execute the script, because /usr/bin/ is in your PATH by default.