Customizing the Bash Shell
Bash Shell Configuration
Bash shell configuration files
As we saw earlier we can create aliases and functions quite easily. However, to make these changes permanent we will probably want to permanently add this so that they are available at login. To configure Bash to use our custom settings we need to configure various configuration files that are used. Some of these files are only executed at "login", others are executed each time a new instance of your Bash shell is started. Some of Bash's configuration files are "System Wide", meaning they will apply to all users of Bash. Many are local and reside in your "/homedirectory/". These local configuration files will only apply to that particular user!
Bash Configuration Files and their Location
|/etc/profile||This is a "System wide" initialisation file that is executed during login. This file provides initial environment variables and initial "PATH" locations.|
|/etc/bashrc||This again is a "System Wide" initialisation file. This file is executed each time a Bash shell is opened by a user. Here you can define your default prompt and add alias information. Values in this file can be overridden by their local ~/.bashrc entry.|
|~/.bash_profile||If this file exists, it is executed automatically after /etc/profile during the login process. This file can be used by each user to add individual entries. The file however is only executed once at login and normally then runs the users .bashrc file.|
|~/.bash_login||If the ".bash_profile" does not exist, then this file will be executed automatically at login.|
|~/.profile||If the ".bash_profile" or ".bash_login" do not exist, then this file is executed automatically at login.|
|~/.bashrc||This file contains individual specific configurations. This file is read at login and also each time a new Bash shell is started. Ideally, this is where you should place any aliases.|
|~/.bash_logout||This file is executed automatically during logout|
|~/.inputrc||This file is used to customize key bindings/key strokes.|
Depending on the distribution you are using, you may not have all of the above mentioned local files. This is perfectly normal.
john@john-desktop:~$ ls -al | grep ".bash" -rw------- 1 john john 26000 Apr 4 20:51 .bash_history -rw-r--r-- 1 john john 220 Oct 22 2011 .bash_logout -rw-r--r-- 1 john john 3384 Oct 12 21:25 .bashrc
The above files were found in my home directory (example from an Ubuntu 14.04 LTS desktop).
The file ".bash_history" is where the commands you have typed are stored. These can be displayed by simply issuing the "history" command or by issuing the "fc -l" command. If you wanted to repeat a command, you can simply specify the number of the command to be repeated. (Please make sure you request the correct command!)
root@john-desktop:~# fc -l 584 cd ~john 585 ls -rtl 586 cat id.txt 587 usermod -G john,adm,dialout,fax,cdrom,floppy,tape,dip,video,plugdev,fuse,lpadmin,admin,sambashare,vboxusers john 588 id john 589 exit 590 set -o vi 591 clear 592 du /tmp 593 du -hs /tmp 594 clear 595 du -hs ~john 596 exit 597 set -o vi 598 fc -l 599 su - landoflinux root@john-desktop:~# !599 su - landoflinux landoflinux@john-desktop:~$
Here we displayed our commands by issuing "fc -l", then I repeated a previously entered command which is identified by the number "599" by issuing !599. This then repeated my previous "su - landoflinux" command.