Wednesday, March 10, 2010

Linux - .profile file

Hey, ur all back...once again !!!
Ive been working on Linux for quite long, but with lot of discontinuities. But this time, while working I thought of learning about .profile and writing one for myself.. Better late than never suits me, isn't it... Ok, enuf talking...Lets get on, like always with BASICS!!!

What is .profile ?
This file is the first file which gets executed when you login to a shell. It has some initializations, aliases, exports etc to make you go easy while working on command line. It is present in the user's home directory and its a hidden file as it begins with a dot(.). So use ls -a.

What do we usually put in .profile ?
Lets say you have a directory /home/mydir/mydir1/ with a lot of files. Now every time you want to do some file manipulation, you obviously wouldn't want to enter the whole path again and again.So we can create an alias and put it in .profile.
alias myd= cd /home/mydir/mydir1/

Functions:
You can also create functions with arguments to simplify ur task. Lets write a function for displaying your file (using cat)
show ()
{
cat /home/mydir/mydir1/$1
}
Now if you write "show abc" from any folder, the file content will be viewed.

set -o vi
This is another command that I always put in my .profile. It enables us to use history.
You can do this by pressing Esc key and then using "k" and "j" to move backward and forward in history. Its useful, believe me...

set -o noclobber
This is again a useful command. It helps us from accidently over writing an existing file.
Lets say you have a file abc.
Now if you write ls -l > abc
You will get an error saying that abc cannot be overwritten.

export HISTSIZE=100
This enables 100 commands to be kept in history.

These are some of things that you can do.You can write if statements and write any kind of shell scripting that you wanna perform at login...

No comments:

Post a Comment