Editing ~/.bash_profile and other hidden files
Files that begin with a .
are called dotfiles, and by default your computer doesn’t show them to us, even on the command line.
Your computer hides them from you because it doesn’t trust you to open them. We’re super, super competent, though, so we’re going to open them anyway!
Prologue: What is ~/.bash_profile
?
One of the files you’ll edit most often is ~/.bash_profile
. It contains all of the setup that happens each time you open up the command line. It tells your computer where to find files, what colors to use in terminal, and all sorts of other stuff.
If we break down the filename ~/.bash_profile
into parts, we find that it is:
- a file called
.bash_profile
- that is located in your
HOME
directory (that’s what~
means) - and just a reminder, the
HOME
directory is something like/Users/yourname/
Method 1: Edit from the command line with nano
If you’re comfortable using the command line, you can use nano
to edit the file.
For example, if you wanted to edit ~/.bash_profile
, you would type the following on the command line.
nano ~/.bash_profile
Now you’re in nano! It’s a very unglamorous text editor, but it’ll get the job done.
- Use the arrow keys and keyboard to make your edits
- Press
Ctrl+O
to Write out (a.k.a save) nano
will ask you for the filename to write out to - just hit enter- Press
Ctrl+X
to edit.
Then you’ll be all set.
Method 2: Edit from your text editor (Atom/Sublime/etc)
This only works in OS X, although I’m sure there are ways to do it in Windows, too.
A lot of people find it easier to edit these files in the text editor. It doesn’t make you less of a Cool Computer Person, and it can be a lot better for complicated changes or long additions.
The problem with opening a dotfile in your text editor is hidden files won’t show up in your file listing, even if you browser to your home directory. To reveal it, follow these steps.
- In your text editor, go to
File > Open
. - Go to your home directory. You can select it from the folder dropdown up top or press
Command+Shift+H
to hop there automatically. - Can’t see the file, right? Press
Command+shift+.
to show all hidden files. If it doesn’t work make sure you’re in the file list view. - Select
.bash_profile
and you’re ready to edit!
To save the file, just save normally.