Page 1 of 1

Customizing You Linux Login Rate Topic: -----

#1 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6643
  • View blog
  • Posts: 30,932
  • Joined: 10-May 07

Post icon  Posted 05 July 2007 - 10:32 AM

Customizing You Linux Login

There are many reasons why someone would want to customize their Linux session. The reasons for this include:
1. Prompt
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.
References :
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.
Start-up order:
/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.

Upon termination:
~/.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:
PS1='\[email protected]\h:\w> ' 

[email protected]:/tmp>

Adding the \A to display the time, we end up with something that looks like this:

10:09 [email protected]:/tmp>

PS1 values: Meaning
\u Username
\h Hostname
\H The fully-qualified hostname
\w Current working directory
\d date
\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
\n newline
\r carriage return

PS1='\e[31m\A\e[0m \[email protected]\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.


alias ls=’ls –color’
alias ll=’ls –l’
alias la=’ls –a’
export EDITOR

(Execute once logged in)
w; cal`date +”%m”` `date +”%Y”`

(Background Jobs)
background_proc &


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.

Is This A Good Question/Topic? 1
  • +

Replies To: Customizing You Linux Login

#2 Tom9729   User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Posted 08 January 2009 - 06:52 PM

My ZSH prompt (~/.zshrc).

setopt appendhistory autocd extendedglob nomatch notify
zstyle :compinstall filename '/home/tom/.zshrc'
autoload -Uz compinit

# Custom colors, borrowed from
# <>
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
	eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
	eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
	(( count = $count + 1 ))

# Custom prompt
function precmd () 
	if [ $TERM = "xterm" ];
	print -Pn "\e]0;%[email protected]%m (%~)\a"

function preexec ()
	print ""

# Custom shell
export PROMPT="$PR_BLUE$PR_MAGENTA%[email protected]%m$PR_BLUE%% $PR_NO_COLOUR"

# Print out a fortune :-)
echo "\n$PR_YELLOW\b\b\b\b$(fortune)"

Prompt looks like this:
Attached Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1