There are many reasons why someone would want to customize their Linux session. The reasons for this include:
You may want to make your prompt different in appearance based on which ID you are logged in. You will also want to change from the default look, & there are unlimited options available for you to use.
2. Environment (variables, libraries, & other situations)
Some hardware may need libraries loaded in order to use the software. You may also take this time to load environment aliases & other customized variables to assist you with your day to day functionality.
3. Background Jobs
At login, you can take advantage of launching processes into the background, so once you get the command prompt, you can expect that your background processes (or daemon) is running.
4. Hardware customization
As in reason #2, you may have some configuration differences for hardware between different users. This would be the ideal time to launch any libraries or configuration variables as needed by the hardware.
5. Xwindows (preparing & starting)
You can even create some session variables specific to Xwindows. You may also want Xwindows to launch as soon as you’ve logged in. Both of these can be handled by your startup scripts.
Bash Shell: The Bourne Again Shell.
Small guide to shell scripting:
Bash Guide for Beginners:
The bash shell checks for a set of files in a specific order. Knowing this order is important so that you can understand when they load & why some of your information may not be available. The following is a list of the startup files in the order they are searched for. If a file is not found, there is no error message, the shell simply skips to the next file.
/etc/profile - This holds the ‘default’ values. So if you want a specific behavior for every user on the system, rather than put it in each users’ .profile file, you can place those actions here.
~/.bash_profile - Login shells. An important fact about this file is that this script is always read, even on new terminal launches or window opens. So in this file you don’t want to launch any background processes that you just want to run once. If you are running Xwindows & open a new terminal window, the background processes will launch again.
~/.bash_login – Login initialization. This file executes once a user is logged onto the system.
~/.profile - login if no .bash_profile is present. In the absence of ~/.bash_profile & ~/.bash_login, this file is read. It can hold the same configurations, which are then also accessible by other shells (for example SH or KSH). This file holds user specific functions similar to the global /etc/profile script.
~/.bashrc - Interactive non-login shells. These shells exist for automatic (sometimes remote) events.
$ENV - Linux by default sets many environment variables for you. You can modify the values of these variables. A few of the variables that are set are:
HOME : The users home directory
PATH : This sets the path that the shell would be looking at when it has to execute any program or reference a file.
PS1 : This is the users’ Shell Prompt.
SHELL : This variable defines the user’s default shell.
LOGNAME : The LOGNAME is automatically set for you, & is the same value as your login name. A situation where you would use this variable is in case you want to reference your login name in a script.
~/.bash_logout - login shells.
~/.inputrc - Readline initialization.
The rc directories
These run prior to being prompted to login. The last one to run will be rc.local, this general runs just after setting up the general purpose mouse device. One main difference between the rc files & what we are talking about here, the rc files run with permissions, so you can setup hardware level configurations.
(setting up common keystroke charactors)
stty erase ^H stty intr ^C stty kill ^X
$PS1 $PS2 prompts:
Adding the \A to display the time, we end up with something that looks like this:
10:09 [email protected]:/tmp>
PS1 values: Meaning
\H The fully-qualified hostname
\w Current working directory
\t The current time in 24 hour HH:MM:SS format
\T The current time in 12 hour HH:MM:SS format
\@ The current time in 12 hour am/pm format
\A The current time in 24 hour HH:MM format
\| The basename of the shell’s terminal drive
\e Escape character
\r carriage return
PS1='\e[31m\A\e[0m \u@\h:\w> '
Which then looks like this:
10:09 [email protected]:/tmp>
Environment (variables, libraries, & other situations)
umask 027 # Create files with group, other permissions turned off. ulimit -c 0 # Prevent a crashed program from creating a "core" file. PATH=$HOME/bin:$PATH:/usr/sbin:/sbin:/usr/local/sbin CDPATH=":$HOME:$HOME/man:$HOME/bin" MANPATH="$HOME/man:$MANPATH" alias ls=’ls –color’ alias ll=’ls –l’ alias la=’ls –a’ EDITOR=vi export EDITOR
(Execute once logged in)
w; cal`date +”%m”` `date +”%Y”`
Q: What if I can’t see my .profile or other files?
A: Try using ls –a. The dot is a generic way of hiding the files from users without super user privileges.