.profile

From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search

The .profile file is used for customizing the user environment. It is the personal initialization file, executed for login shells.

.profile file execution order

When a user logs in using sh or ksh, the system run in the following order:

  1. /etc/profile
  2. $HOME/.profile
  3. $HOME/.kshrc (ksh)

Example .profile script

# TERM=xterm; 	export TERM

EDITOR=vim;   	export EDITOR
PAGER=less;  	export PAGER

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV

# Let sh(1) know it's at home, despite /home being a symlink.
if [ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] ; then cd ; fi

# Query terminal size; useful for serial lines.
if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi

# Load bash completion
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] && \
	. /usr/local/share/bash-completion/bash_completion.sh

# Display a random cookie on each login.
if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune freebsd-tips ; fi


alias monitor_off='sudo sysctl  hw.acpi.video.lcd0.active=0'
alias ls='ls -G'
alias ll='ls -G'
alias vi='vim'
alias cputemp="sysctl -a | grep -E 'acpi.thermal.*temperature|dev.cpu.*temperature'"
alias grep='grep --color'

clear

How to set or modify a path in Unix using .profile file

The PATH environment variable is a colon-delimited list of directories that sh or ksh searches through when entering a command. First, edit the file .profile in the $HOME:

vi ~/.profile

Append / modify PATH as per your needs. For example:

PATH=$PATH:/home/admin/bin ; export PATH

This makes the PATH setting permanent when using sh or ksh. We can verify by typing the following echo command or printf command:

echo "$PATH"

.profile file equivalent in other shells

  1. .cshrc file for csh and tcsh
  2. .profile file for sh and ksh
  3. .bash_profile file for bash