How to edit .bash_profile and .bashrc files?
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"
codes in the above files.
Please help me with this.
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.
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
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:
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.
To update .bash_profile n .bashrc u hv to be in home directory of user...
so type following at the command prompt
update the profile and rc files...
this will work...
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.
@discoverlego....thanks man your answer helped me edit my .bash_profile today.
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.)
|All times are GMT -5. The time now is 02:52 AM.|