Best way to organise one's sh/bash/python/etc. scripts

What is the best way to organise the sh/bash/python scripts you collect and write on your system?


I have all such scripts in ~/bin which also is a svn working for all the scripts I frequently use on multiple computers. It also contains parts of my zsh configuration like aliases and environmental variables.

Depends on the purpose of the script. I generally break mine down between one of two locations. Either ~/tools for serious stuff I reuse on a regular basis or ~/playground/[name of feature I'm toying with].

I have a ~code directory, with a subdirectory for every language I use, and in my .bashrc I have an instruction to source every one of them to my $PATH. For example:

[email protected]:~ $ cat .bashrc
export PATH="$(
    find /home/dsm/code -mindepth 1 -maxdepth 1 -type d -print\
        | perl -ne 'chomp; print"${_}:";'
)${PATH}" ;
[email protected]:~ $

Much like everyone else here, I go with ~/bin for most scripts, and leave project specific things under ~/projects/whatever.

What I do is this:

Have /home/myname/Scripts/

I put all my scripts there (classifies in directories based on their function/project). Now the best part is, the entire /home/myname/Scripts/ is version controlled (with SVN). This way, I can modify and still can look back at my changes.

for all the apps to recognize this, you can try adding the path to /etc/profile (for bash).

in /etc/profile, last line, add

export PATH=${PATH}:/home/myname/Scripts/

Currently I'm storing everything in a folder in my home directory, ~/sh. I have added it to the PATH in .bashrc (and .zshrc, since I use both.)

The flaw is that applications that are not started by a terminal, like the X server, do not pick up the modified value of PATH. I am then forced to prepend 'sh/' to the file name when I launch those scripts from the graphical interface.

Most scripts I write are specific to a certain project, so I just leave them in the directory for that project. You don't have to add them to any PATHs, and it's easy to remember what they're for.

For global scripts on the other hand, a ~/sh directory sounds like a winner.

Under windows, you can set system-wide environment variables either for all the users or for a specific user.

This means that whenever a program starts it knows the environment variables you set. Of course, you can also set the environment variables from another process, such as CMD, and in this case only programs that are being started from this process will know those variables.

I don't know a way under Linux to set system-wide environment variables for specific users, but there is a way to set system-wide environment variables for all the users.

you can write the value you want in this file: /etc/environment

Values set in this file will be recognized by all the programs, for all the users.

You can do 'man pam_env' to get more information about the daemon that actually process this file.

Hope it helps,

Jonathan Orlev

I keep all my frequently used scripts in ~/scripts and have configured my /etc/profile to include that folder in my path for all users.

if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then


For frequently used scripts I'm using ~/bin. You also may want to set something like

export PATH=/home/USER/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

in the ~/.bashrc file to add own scripts to executables search ath. But this method is very unsecure, and I recommend everyone always use full paths to all executables including ones in ~/bin. E.g. /usr/bin/sudo instead of just sudo.

I keep all of my development stuff under user\dev, which is symlinked to my dropbox folder, to keep everything backed up. (ok, I lied, most graphical stuff is in dev\..\graphics to reduce dropbox usage for things that don't need to be backed up as often)

Scripts stay in dev, and if I find myself using them often I'll alias something to them, rather than having everything in there on my path. ('alias' here referring to doskey, which I automated with a python script which I aliased to alias)

I put all my scripts (anything that is potentially platform independent) into ~/cmd and prepend that (and a bunch of other stuff) to PATH in my .zlogin and .bash_profile.

I use ~/bin for some hand-installed platform-specific binaries (or symlinks to such binaries).

Keeping the platform/machine-specific stuff out of ~/cmd makes it easier to copy it from machine to machine (I have mine in Git to provide history and transportation between machines).

Category: linux Time: 2008-09-17 Views: 4

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.223 (s). 12 q(s)