Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-22-2008, 11:09 PM   #1
LQ Newbie
Registered: Sep 2008
Posts: 21

Rep: Reputation: 15
How to edit .bash_profile and .bashrc files?

Respected Sirs,

I am trying to edit .bash_profile and .bashrc files. I dont know how to do this.
I tried vi .bash_profile and all I get is just few lines printed as below:
I am unable to add/delete anything here.
Could anyone please tell me how to edit this file.
Do I need to have superuser priveliges?
If yes, then what is an alternative?
Can I create this file in my own local (default 'cd ~' directory)?
I actually tired creating this file in my local directory but it seems like it is not working.

I am trying to add
alias dir="ls -a"
alias typeout="cat"
codes in the above files.
Please help me with this.

Old 10-22-2008, 11:20 PM   #2
Registered: Sep 2008
Distribution: CentOS
Posts: 75

Rep: Reputation: 16
try vi /home/<username>/.bashrc or .bash_profile

Also , the line of tilda's means you are now in the vi editor and the tilda's represent lines on the screen that do not exist in your file. To get into insert mode type 'i', then you should be able to type what you want. When you are finished hit the escape key and type :wq and hit enter. This will exit and save changes.

VI can be very powerful, but very hard to work with at first. See this reference for more vi commands.

Last edited by centos82; 10-22-2008 at 11:33 PM.
Old 10-22-2008, 11:25 PM   #3
Registered: Jun 2008
Location: Ottawa, Ontario, Canada
Distribution: debian, dsl-n
Posts: 55

Rep: Reputation: 15
Try nano .bash_profile. Nano is an easy to use editor and is included with most Linux distributions. If you are stuck with vi,then here is the basics.

Vi has 2 modes, command and append. when you start vi, it is in command mode. The ~~~ are blank spaces. You can move the cursor around, but not type. Press the "a" for append to add text. When you are finished editing, press the "esc" key to go back to command mode.

Summary of commands:

a Edit Mode
esc Command Mode
You must be in command mode for these to work:
:w + enter Save file
:x + enter Save and exit
:q + enter exit
:q! + enter exit without saving
Old 10-22-2008, 11:30 PM   #4
LQ Guru
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 11
Posts: 8,153

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Different distributions use different names for the bash startup file. It could be .bash_profile, .bashrc, or .profile.

There is one of these default files for each user including root. Each user can edit his own startup file without needed root privileges. So look in /home/username and see what filename your distribution uses for a bash startup file and edit that.

Each distribution also has a universal default bash default file somewhere in /etc. In Debian it is called /etc/profile. Other distributions may give it a different name. You need to be root to edit this file. If you specify a default in both /etc/profile and your user bash startup file then the user file takes precedence.

Here is an explanation about how bash startup files work in Linux From Scratch:

Steve Stites
Old 11-02-2008, 07:45 AM   #5
Registered: Oct 2008
Posts: 37

Rep: Reputation: 16
Personally, I never liked VI. If you are a newbie to VI - I'd suggest you use GEDIT instead.
It is a simple and neat text editor (similar to the notepad application on Windows).

It would make life a lot more simpler for you.

Linux Archive

Last edited by nishamathew1980; 11-09-2008 at 05:52 AM.
Old 11-04-2008, 12:30 AM   #6
LQ Newbie
Registered: Aug 2008
Posts: 1

Rep: Reputation: Disabled
To update .bash_profile n .bashrc u hv to be in home directory of user...
so type following at the command prompt

$cd ~

$vi .bash_profile

update the profile and rc files...

this will work...

Last edited by discoverlego; 11-04-2008 at 12:33 AM.
Old 11-27-2008, 06:51 AM   #7
LQ Newbie
Registered: Oct 2007
Posts: 1

Rep: Reputation: 0
The post from jailbait was very helpful. I am using a debian-etch distro which is very reliable. But for the mewbie it is very complicated especially the location of the startup files. I was able to find both .bashrc and .bash_profile under /home/username as was suggested but you have to enable system and hidden files in the view part of the directory menu for /home/username. A little gotcha. Thanks for the help.
Old 07-21-2012, 08:35 AM   #8
LQ Newbie
Registered: Jul 2012
Posts: 1

Rep: Reputation: Disabled
@discoverlego....thanks man your answer helped me edit my .bash_profile today.

Old 07-21-2012, 09:46 AM   #9
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,427
Blog Entries: 1

Rep: Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679
Anyway, you have to learn to use at least one text-editor if you want to use your system effectively. There are many possibilities both in GUI and terminal.
(I prefer mcedit -- very easy to use for people who knew Norton Commander.)
Old 07-21-2012, 10:19 AM   #10
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Originally Posted by valiantvimal View Post
@discoverlego....thanks man your answer helped me edit my .bash_profile today.

You really didn't have to drag up such an old thread just to post that. Please avoid doing so in future.


bash, debian, startup

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bashrc vs. bash_profile mikeshn Linux - General 9 02-10-2008 02:46 PM
.bashrc .bash_profile Soulful93 Slackware 4 05-03-2005 04:02 AM
~/.bashrc, ~/.bash_profile Sinope Linux - Newbie 6 08-17-2004 03:40 AM
.bashrc or .bash_profile? statmobile Linux - Newbie 1 02-04-2004 10:08 PM
.bashrc vs .bash_profile xor3 Linux - Newbie 1 08-16-2003 01:52 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration