Where (in which directory) to store shell scripts ?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Where (in which directory) to store shell scripts ?
Hello everyone,
I am trying to transition from Windows to Linux, and I have to start by changing my habits one by one.
For my various day to day tasks, I wrote a few scripts (backup, archiving, etc.) and I was wondering if there is a preferred directory where I should store them.
Right now, they are all sitting in /home/bob/script. I was wondering, should I rather store them in /usr/bin , or is this only used for binaries ?
The beauty of unix is the idea that you can put just about anything anywhere. But naturally there are a lot of traditional arrangements for the file system. As long as you're only using the scripts as a single user, your current location is just fine. But if you want them to be accessible system-wide, then somewhere in the /usr directory is probably best. /usr/bin is mostly for the distro-installed stuff, and /usr/local/bin is where the stuff you write or compile yourself usually goes (most source packages default to installing there, for example).
Wherever you decide to put them though, you can add the directory to your PATH environment variable so they'll be easily accessable by the system (i.e. you won't have to type the entire path to the script in order to run it).
It is right that you can put your scripts nearly everywhere in Linux. You can accustom anything. However it makes sense to abide to existing standards like the File Hierarchy Standard [1]. Therefor I would recommend /home/username/bin , /usr/bin or /opt/scriptfunction/
Thanks for all the replies.
I was mostly looking for a "best practices" type of approach.
They are going to remain in /home/bob/script then.
Not advisable in general. If you leave the company and forgot to tell your successor that your scripts are stored there, he might remove your account and all files inside (just an example, but who knows, right).
Just some recommendations:
In your environment, you should set up a designated place in your production system to store your files. For example, for data files, you can create partitions or folders and name it data (up to you)
eg
/production/data
then under this folder/partition, you can create other folders for various systems in your environment that needs to generate data for storage of further processing.
eg
/production/data/financial
For storing scripts that are run in cron job, you can, for example, create partition/folders and name it
eg
/production/binaries
Then create subdirectories for each systems and put your scripts there
eg
/production/binaries/financial
I won't advise putting into /usr also, simply because you might forget(or someone else) and then you wipe your OS for upgrade.
You should probably discuss with your superiors about all these and how to go about organizing your servers.
Last edited by ghostdog74; 12-31-2007 at 10:14 AM.
/usr/local/bin was created for such things. /usr/bin is a default for binary programs and installs. Put your own scripts in /usr/local/bin. Usually this is already in your default PATH as well.
IMO, own written scripts for production should have a place of its own, for better management and not confusing them with those in /usr/local/bin.
/usr/local/bin are usually for third party installation packages.
IMO, own written scripts for production should have a place of its own, for better management and not confusing them with those in /usr/local/bin.
/usr/local/bin are usually for third party installation packages.
Just depends where you install 3rd party applications, most of the time those go in /usr/bin for me. It's all a matter of opinion and preference. There is no wrong answer, except the /home directory, that's for users own files, not files to be used by everyone.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.