I usually have my scripts on a folder in my home directory, and then to make them executable from anywhere I just create a symbolic link to the script in a path folder. Cheers!
Just make sure to backup usr/local/bin if you upgrade your linux version. Also, i think using the export command that way only changes your path for that session.
I really like your videos and would like to thank you for all your work. In this video a small carelessness has crept in, to which I would like to draw attention briefly. At minute 6 after ls -l /usr/locacl/bin you see the following output: "-rwxrwxr-x" (775) However, it would be better and above all safer to set the permissions as follows: "-rwxrwxr--" (774) This way only root or root privileged user can execute this command. Hope this helps. Thanks again for your wonderful work. - Big THANK YOU!
Your solution seems indeed cleaner since others have no business executing the command. But could a non-privileged user actually execute this script even though it contains sudo commands? Very late reply, but would be very curious since I am just starting to get into this stuff.
I use ~/.local/bin/ for my scripts mainly because it is added to the $PATH (if present) via the .profile file (it also looks for ~/bin/ directory as well). This works for me as I have a single user system, however I would use /usr/bin/ as Jay suggests to make it system wide if I had more that one user.
Does "export" to reconfigure the $PATH work only in that shell? I think so but I can't test it at the moment. Seems to me that we need a script that sets $PATH whenever we open a new shell.
I mostly keep my scripts in /home/$USER/scripts or /home/$USER/.local/bin because mostly it's just me using them; the .local/bin directory is in my $PATH but scripts is not. I find the Linux Filesystem Hierarchy Standard a little confusing, or maybe it's confused (even that's confusing). You're not supposed to create directories off the root, but the standard Linux directories seem liable to be not updated properly if you e.g. have to reinstall or you have a new installation. On Windows every app goes under the Program Files directory and e.g. Windows and Windows\System32 is not (usually these days) updated with user or application binaries. On Linux you have a plethora of directories under /usr and there's also the /opt directory if you're installing an application, maybe. Some apps install themselves there, some go in various directories under /usr. It doesn't seem like there are hard and fast rules as to what goes where, and I know that files go in slightly different locations on different distros which makes it even more confusing! If you're a developer with several users on a machine and you want to share source and include files for example, where are you supposed to put them? Include files probably go under /usr/include. but you don't really want to put them there because that's a distro-created directory that contains files specific to the C compiler. You could create a subdirectory but of course that won't be migrated to a new system without manual copies. Source files probably go somewhere under /usr/share or /usr/src or maybe it's /var. I really find it difficult to know where files should go that won't interfere with system/distro-provided files, and which won't get clobbered or left out on a system upgrade or migration. These days I'm considering putting my source and includes in containers and accessing them via HTTP or SMB e.g. (or NFS if I can ever figure it out). That won't answer my questions regarding directory hierarchy, but will make migration more straighforward, in theory.