LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 12-28-2007, 11:31 AM   #1
jeepescu
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Rep: Reputation: 0
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 ?

Thanks in advance,
BN
 
Old 12-28-2007, 11:46 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
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).
 
Old 12-28-2007, 12:51 PM   #3
brianmcgee
Member
 
Registered: Jun 2007
Location: Munich, Germany
Distribution: RHEL, CentOS, Fedora, SLES (...)
Posts: 399

Rep: Reputation: 38
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/

[1] http://www.pathname.com/fhs/pub/fhs-2.3.html
 
Old 12-28-2007, 01:07 PM   #4
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,474

Rep: Reputation: 155Reputation: 155
I recommend that you store your scripts somewhere in /home/user as this makes life easier when you upgrade your operating system.

--------------------
Steve Stites
 
Old 12-28-2007, 01:37 PM   #5
jeepescu
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 12-31-2007, 08:46 AM   #6
samash
Member
 
Registered: Jun 2006
Location: Delaware
Distribution: Redhat, Fedora
Posts: 43

Rep: Reputation: 15
/usr/local/bin
 
Old 12-31-2007, 09:08 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Quote:
Originally Posted by jeepescu View Post
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 09:14 AM.
 
Old 12-31-2007, 10:05 AM   #8
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
/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.
 
Old 12-31-2007, 11:22 AM   #9
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Quote:
Originally Posted by trickykid View Post
Put your own scripts in /usr/local/bin.
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.
 
Old 01-01-2008, 07:56 AM   #10
brianmcgee
Member
 
Registered: Jun 2007
Location: Munich, Germany
Distribution: RHEL, CentOS, Fedora, SLES (...)
Posts: 399

Rep: Reputation: 38
Ideally scripts for production are embedded in a package like deb or rpm so that no one forgets about them ;-)
 
Old 01-01-2008, 08:01 AM   #11
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
Quote:
Originally Posted by ghostdog74 View Post
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.
 
  


Reply

Tags
directory, script, shell, store


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell scripts unable to permanently change directory after exit ernesto_cgf Linux - General 4 12-21-2006 04:08 PM
Shell scripts shmuel_orgad Programming 4 05-21-2006 05:33 AM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM
shell scripts newbie_m Linux - Newbie 3 01-18-2005 08:12 PM
in which directory user mail store in Redhat 9 nazib Linux - Software 1 12-08-2004 02:33 AM


All times are GMT -5. The time now is 11:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration