Where should I put my script so that I can run it by a direct command?

It depends on who will use your script:

  • Yourself only - $HOME/bin like @waltinator said
  • You and other local users - /usr/local/bin
  • root only - /usr/local/sbin

That way you have your own scripts separated from the distribution-provided binaries.


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.


You should put your script under $HOME/bin. Follow below PATH to achieve this:

  1. Create a folder using mkdir $HOME/bin
  2. Then put your script in $HOME/bin

  3. 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.