LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to edit .bash_profile and .bashrc files? (http://www.linuxquestions.org/questions/programming-9/how-to-edit-bash_profile-and-bashrc-files-678445/)

LinuxInfo 10-22-2008 10:09 PM

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,

centos82 10-22-2008 10:20 PM

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/

wernerz 10-22-2008 10:25 PM

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

jailbait 10-22-2008 10:30 PM

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

nishamathew1980 11-02-2008 06:45 AM

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

discoverlego 11-03-2008 11:30 PM

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...

chuckw 11-27-2008 05:51 AM

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.

valiantvimal 07-21-2012 07:35 AM

@discoverlego....thanks man your answer helped me edit my .bash_profile today.

Regards,
Vimal.

NevemTeve 07-21-2012 08:46 AM

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.)

Nylex 07-21-2012 09:19 AM

Quote:

Originally Posted by valiantvimal (Post 4734480)
@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.


All times are GMT -5. The time now is 09:20 PM.