169

I feel stupid asking, but I can't seem to find the answer to this anywhere. I'm trying to follow these instructions to edit my bash prompt, but there is no .bashrc in either my user directory (~/.bashrc), or in my home directory, or in the main file system directory.

There is no .bashrc in /etc/ (there is a bash.bashrc, however).

Do I create a .bashrc file in my user or home directory? Is there a better, more recent set of instructions for modifying the bash prompt?

Charo
  • 3,581
  • 2
  • 20
  • 36
JeanSibelius
  • 3,522
  • 7
  • 23
  • 27
  • 2
    You do not need to find/edit .bashrc in `/etc/`. There should be a *.bashrc* file in your home directory. Try to open/edit `~/.bashrc`. But before that I should also ask if you are new to Linux. If you are new to Linux, then I can post detailed instructions here. – Ankit Apr 28 '12 at 15:44
  • 2
    All of the above answers recommend putting your aliases in `.bashrc`, but [you should put them in `.bash_profile`](http://askubuntu.com/questions/121413/undertanding-bashrc-and-bash-profile) **Edit** To clarify, don't create a `.bashrc` if it's just for this, create or modify `~/.bash_profile` – Louis Maddox Jul 09 '14 at 13:33
  • 3
    @Louis Defining aliases in `.bash_profile` is wrong. In Ubuntu `.profile` (which runs for login shells) sources `.bashrc` when it's an interactive bash shell. So putting aliases in `.bashrc` (or `.bash_aliases`, sourced in `.bashrc`) defines them in *all* interactive bash shells. Aliases in `.bash_profile` yields [this problem](https://askubuntu.com/q/109985), and others. See [this](https://askubuntu.com/q/17536), [that](https://askubuntu.com/q/1414), [this post](https://askubuntu.com/a/606882), and the default `~/.bashrc`'s comments recommending putting aliases there or in `.bash_aliases`. – Eliah Kagan Apr 08 '15 at 18:50
  • 2
    Oh wow, I'm very sorry if I've misled anyone. I wrote that comment just a few months into using Linux. Peculiarly I do now have them in `.bashrc` and sourced my `.bashrc` in `.bash_profile` with code copied from [this SuperUser answer](http://superuser.com/a/163268/244556) ("*Get the aliases and functions*"). Thanks for correcting these commonly viewed questions Eliah, [really nice answer here](http://askubuntu.com/a/606882/266014)! – Louis Maddox Apr 08 '15 at 18:56
  • Answer for similar question for Windows is here [Git for Windows: .bashrc or equivalent config files for Git Bash shell](http://stackoverflow.com/a/6883798) – Michael Freidgeim Feb 16 '16 at 23:45
  • Here is one highly related topic: [At what point is the ~/.bashrc file created?](https://askubuntu.com/q/971836/566421) – pa4080 Dec 29 '22 at 19:09

11 Answers11

184

Don't forget it is a hidden file inside your home directory (you would not be the first to do a ls -l and thinking it is not there).

Do a:

ls -la ~/ | more

There should be a .bashrc on the first page. If not just create it with:

vi ~/.bashrc

and add in the lines you need to add into it.

Permissions of my .bashrc are:

-rw-r--r--  1 discworld discworld  3330 Mar 10 16:03 .bashrc

(chmod 644 .bashrc to make it rw r r).

Radu Rădeanu
  • 166,822
  • 48
  • 327
  • 400
Rinzwind
  • 293,910
  • 41
  • 570
  • 710
44

User specific, hidden by default.

~/.bashrc

If not there simply create one.

System wide:

/etc/bash.bashrc
Alen
  • 586
  • 4
  • 4
17

There is a .bashrc in every user's home folder (99.99% of the time) as well as one system-wide (which I don't know the location of in Ubuntu).

The quickest way to access it is nano ~/.bashrc from a terminal (replace nano with whatever you like to use).

If this is not present in a user's home folder the system-wide .bashrc is used as a fallback as it is loaded before the user's file. You could simply copy and paste it (with root permissions of course), but a .bashrc is not entirely essential (it may be required to make things work. I haven't found out) at a user level as it mostly overrides the system-wide one with user-specific tweaks. You could write your own though.

The main components for that users may tweak are PS1 (the Bash prompt defaults to display user@localhost:pwd $) and aliases as well as setting a color prompt and maybe PS2 (busy state message).

Peter Mortensen
  • 933
  • 2
  • 11
  • 17
MuffinStateWide
  • 849
  • 5
  • 13
14

Use gedit ~/.bashrc, it will allow you to modify ~/.bashrc using gedit.

kos
  • 35,535
  • 13
  • 101
  • 151
adonese
  • 141
  • 1
  • 4
6

It is hidden because of the '.' it starts with.

list it with

ls -al

or enable "show hidden files" under the view menu in nautilus (Ctrl-H will also do the trick).

You can edit it with your favorite text editor from your home directory e.g.

cd

to go to your home directory then:

emacs .bashrc

haziz
  • 2,899
  • 9
  • 36
  • 48
5

If .bashrc is not in your home folder, even after you list the hidden files, you can copy it from:

/etc/skel/.bashrc
heemayl
  • 90,425
  • 20
  • 200
  • 267
eaykin
  • 151
  • 1
  • 2
3

if not in home directory, you can just copy from /etc/bash.bashrc, and make it source for your terminal, by typing in your terminal source .bashrc from your home directory after copying.

Mudit Kapil
  • 1,991
  • 7
  • 29
  • 45
3

Use nano ~/.bashrc to open and edit the .bashrc file. (This will create the file if it does not yet exist)

Nick Weinberg
  • 4,555
  • 4
  • 24
  • 30
gsshakil
  • 31
  • 1
0

Bashrc file is a hidden file inside the home directory. It is actually, give the path directions.

And those are wanted to edit .bashrc file, try this command gedit ~/.bashrc instead of this ~/.bashrc .

This command gedit ~/.bashrc directly take you to the text editor, where you can edit it easily, as you know.

sd_Dhara.45
  • 111
  • 4
0

Just one note: after you made your alias in bashrc, you need in your terminal to write following command in order that your aliases work:

source .bashrc

Personally, whenever I install Linux anew, I add some aliases finding an appropriate place in .bashrc E.g.

#My aliases
alias shut='shutdown now'
alias x='exit'
alias update='sudo apt-get update'

Etc. You get the idea.

Zed Pi
  • 31
  • 1
0

If you use encryption and work from the command line you might not see it as one need to mount the real home-dir first (in contrast to in the graphical UI where this is done automaticallu) by the command:

ecryptfs-mount-private

(I had the same question and stumbled upon this question; but found my answer in the readme instead)