LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-22-2008, 10:09 PM   #1
LinuxInfo
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"
and
alias typeout="cat"
codes in the above files.
Please help me with this.

Thanks,
 
Old 10-22-2008, 10:20 PM   #2
centos82
Member
 
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.
http://http://www.digilife.be/quickreferences/QRC/vi%20Quick%20Reference.pdf/

Last edited by centos82; 10-22-2008 at 10:33 PM.
 
Old 10-22-2008, 10:25 PM   #3
wernerz
Member
 
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, 10:30 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
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:

http://www.linuxfromscratch.org/blfs...s/profile.html

-----------------------
Steve Stites
 
Old 11-02-2008, 06:45 AM   #5
nishamathew1980
Member
 
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 04:52 AM.
 
Old 11-03-2008, 11:30 PM   #6
discoverlego
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-03-2008 at 11:33 PM.
 
Old 11-27-2008, 05:51 AM   #7
chuckw
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, 07:35 AM   #8
valiantvimal
LQ Newbie
 
Registered: Jul 2012
Posts: 1

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

Regards,
Vimal.
 
Old 07-21-2012, 08:46 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,865
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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, 09:19 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

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

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


Reply

Tags
bash, debian, startup



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 01:46 PM
.bashrc .bash_profile Soulful93 Slackware 4 05-03-2005 03:02 AM
~/.bashrc, ~/.bash_profile Sinope Linux - Newbie 6 08-17-2004 02:40 AM
.bashrc or .bash_profile? statmobile Linux - Newbie 1 02-04-2004 09:08 PM
.bashrc vs .bash_profile xor3 Linux - Newbie 1 08-16-2003 12:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:15 PM.

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