If I have a custom shell script or programs, that I created myself or downloaded from the web, and I want to be able to execute this from the CLI, is there the standard location to put this in Linux/Unix directory structure?
/usr/bin ?
/usr/local/bin ?
/usr/lib ?
/usr/sbin ?
/bin ?
/sbin ?
/var ?
I usually put it under my ~/bin folder and put it in PATH, but it doesn't seem clean. And everytime I downloaded a new program, I have to put it in the PATH again.
/usr/local/bin
exists precisely for this purpose, for system-wide installation. For your own private use,~/bin
is the de facto standard.If you want to keep each binary in its own subdirectory, you can do that, and add a symlink to a directory already in your
PATH
. So, for exampleprovided
$HOME/bin
is in yourPATH
. (There are tools likestow
which do this -- and much more -- behind the scenes for you.)This may vary slightly depending on the Unix flavour. I'm assuming Linux here (although this could apply to OSX). According to the Filesystem Hierarchy Standard (FHS) (link obtained from the Linux Standard Base working group):
/usr/local/bin
is often on the path by default.Note that you should only put the executable or a link to it in
/usr/local/bin
, the rest may have to go in/usr/local/lib
or/usr/local/share
.The
/opt
tree might also be sensible:(You could make your own link from
/opt/your-package/bin/executable
into/opt/bin
, and put/opt/bin
on thePATH
if it's not already there.)Well I would use
~/bin
(while I'm not root), but regarding$PATH
you can always doThis way the actual working directory always will be in your
$PATH
. Although it has some security issues... especially with downloaded scripts.