Tuesday, November 30, 2010

About .bashrc .bash_profile .profile .bash_login and /etc/profile

Have you ever wondered what is the purpose of ~/.bashrc ~/.bash_profile ~/.bash_login ~/.profile and /etc/profile files in Linux.

Bash is the default shell on most of the Linux distributions like Fedora and Ubuntu. If you take a look at man pages for Bash, you will get the following explanation:
When bash is invoked as an interactive login shell, or as a  non-interactive  shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.  
When  an  interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exist. 
Interactive shell is the one which is not running because of a script and lets you enter commands to interact with it. Login shell is the one where you are asked for user name and password before you can enter commands. An example of an interactive login shell is the one that you get after you login to a system using ssh. An example of non-login interactive shell is a shell that you get when you run terminal from menu item or some icon.

So when you login to a Linux system, first commands from /etc/profile (if it exists) will get executed. Then the system will look for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and execute commands from the first of these files that it founds. And when you open Konsole/Terminal from KDE or GDM, first commands from /etc/bash.bashrc (if it exists) will get executed and then commands from ~/.bashrc (if it exists) will get executed.

So if you want to execute a command for all users then you will need to add it to /etc/profile but if you want a command executed for a specific user then you can add it to .profile, .bash_profile, .bash_login or .bashrc in his/her home directory.

Please keep in mind that KDE and GDM are not login shells so there behavior is different. I dont know about KDE but GDM first executes command from /etc/profile and then from ~/.profile.

Tuesday, November 23, 2010

Extreme Programming is overrated

Xtreme Programming is a seriously flawed technique. As development methodology XP is nothing new. Iterative development was first explained by Spiral model which was introduced back in 1986. Also, few of its basic rules, most notably Peer Programming and Collective Ownership, are really against the management sense.

Peer programming simply wastes a resource. One guy writing the code and other just watching him write the code is just non-sense. Why not let both of them write their own code and review each-other's code at the end of the day? It is also very difficult to pair the right programmers together as not all programmers are made equal. So if you pair a good programmer with a not-so-good-programmer then the results will suffer, the productivity of the pair will be lesser than the productivity of the good programmer working alone as he will need to explain him self quite frequently. Programming is not an exact science. Its an art and programmers, like musicians, painters, writers, work well when left alone. You wouldn't want Picasso and Michael Angelo working on the same painting, would you?

Collective ownership diminishes the individual sense of ownership and responsibility. For a highly productive work environment, it is important to develop sense of ownership in the work force. As employees (developers in our case) develop sense of ownership there is an increased sense of pride, motivation and self-esteem. This results in increased productivity. If you want great software, let the developers own what they create.

In my opinion, XP is overrated and unpractical. Some of its ideas like Test First Development, Refactoring and Integrate Often work well but they are not specific to XP. Others like Pair Programming and Collective Ownership really make no sense.

Monday, November 15, 2010

Linux Directory Structure

The first thing that troubles a Linux newcomer is the Linux directory structure. First thing that people need to understand is that Linux has one directory tree which starts at "/" (also known as "root directory" or simply "root") in contrast Windows has multiple directory trees, one for each partition and removable media.

Every formatted hard drive partition has a file system on it. These file systems are not required to be the same. In Windows each file system is mounted to a different drive letter, thus starting a new directory tree, whereas on Linux one file system is mounted on root i.e "/" and other file systems are mounted on subdirectories of the root file system, creating a single directory tree. The file system mounted on "/" is called Root File System.

Given below are the most important subdirectories of root directory:

This directory contains the programs(binaries) that are required during bootup. These programs may be run by root user as well as a normal user. There must be no subdirectory in /bin.

This directory is similar to /bin as it also contains binaries that are required during bootup but these binaries can only be run by super user i.e root user.

This directory contains library files that are required by different binaries in /bin and /sbin.

Similar to /bin except that it contains programs which are not required during bootup.

Similar to /sbin except that it contains programs which are not required during bootup.

This directory contains library files that are required by different binaries in /usr/bin and /usr/sbin.

This directory is analogous to "Documents & Settings" directory in Windows. It contains 1 directory per user known as home directory of that user. All user specific files, configuration, documents and etc are stored in the users home directory.

This directory contains boot loader files. Boot loader is a program that boots Linux.

This directory contains system wide configuration files e.g network configuration, XWindows configuration and etc.

This directory contains variable files i.e the files whose content changes continually during the operation of a system. An example of such files are log files which can be found at /var/log directory

More on Linux Directory Structure can be found at Filesystem Hierarchy Stadard website and on Wikipedia