This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
If this question can be reworded to fit the rules in the help center, please edit the question.

@Ian Kelling: What I'm actually saying is that operations that should be performed once per login belong in .bash_profile and operations that should be performed once per shell instantiation belong in .bashrc.
–
chaosMay 4 '09 at 11:43

I used to set these up all over the place but then realized that it was better to just remember how to do them 'manually' because it meant I would 1) fully understand what was going on and 2) have access to these capabilities even if my custom .bashrc wasn't installed.

The only thing I use aliases for these days are to cut down on repetitive typing of really long lines (eg. alias myhost='ssh -T user@my.remote.host screen -dAr' )

Since I use so many different machines, my .bashrc always sets the command prompt to include, among other things, the name of the server I am currently logged into. This way, when I am three levels deep in telnet/ssh, I don't type the wrong thing in the wrong window. It really sucks to rm -rf . in the wrong window! (Note: At home, telnet is disabled on all machines. At work, ssh is not always enabled and I don't have root access to very many machines.)

I have a script ~/bin/setprompt that is executed by my .bashrc, which contains:

Unfortunately, awhile back I launched a shell from cron which didn't read .bashrc somehow, and chopped everything down to 500 lines, destroying over a years' history. So I recommend these go in /etc/bashrc.

I've had this in my .bashrc for a while and I've found it helpful. If you are sshing in to the box, is starts screen automatically when you login, that way when your network connection gets interrupted or whatever, you don't lose whatever you were doing. It should be placed at the end.

I would echo @pjz's comment about knowing things manually rather than setting them up. Especially if you access numerous machines, like I always seem to do.

So one I definitely know is set -o vi because I know the vi-editing commands in bash and I don't know the emacs ones (besides, Ctrl+A interferes with screen). On my own boxes, I put that in .bashrc

I also find I have to include export EDITOR=vim because a number of recent distros default to nano which is most annoying to be thrown into by a utility that needs you to edit something, when I was expecting vi. :-/

I also alter my prompt. I found a long long time ago that adding the last error code is just useful enough that I like it. And I like the full pathname in the prompt. And the current screen number, too. And it just makes sense to include the current user and hostname. My prompt is PS1='\u@\h $PWD $WINDOW [$?] \$ '

That way, if I know that I've done something before but can't remember the specifics, a quick history | grep foo will help jog my memory.

I often found myself piping output through awk in order to get a certain column of the output, as in df -h | awk '{print $2}' to find the size of each of my disks. To make this easier, I created a function fawk in my .bashrc:

If you need to specify a delimiter (e.g., awk -F: for /etc/passwd), this function obviously can't handle that. The slightly-overhauled version in this gist can handle arbitrary awk arguments before the field number (but still requires input from stdin).

Have bash check to see if the window size has changed (prevents line-editing from going weird if you resize your terminal window)

shopt -s checkwinsize

This is my favourite. Causes bash to append to history instead of overwriting it. Typically when you launch bash, it loads history into memory, and when you close it it writes it out. This means that if you load two shells, use both, then close both, the one you closed last overwrites all changes.

This snippet causes it to first of all only append changes (instead of overwriting with the whole buffer), and then to cause it to, after every command, write out changes. In effect, you get a live updating .bash_history, so if you start a new terminal, you have all the commands from your other running sessions' history.

I'm addicted to screen, and I use the following shortcuts for SSHing to machines. With this script, I type p hostname to SSH to a host and run screen, or o hostname to do the same but run screen on the local machine.

First a script that connects to an SSH server of the same name as the script you're running. I call this simple_ssh:

The $SCREEN environment variable lets you automatically execute GNU screen with the connection. SCREEN=1 runs screen locally (say, if screen is not installed on the host) and SCREEN=2 runs it on the host itself.

Use a couple aliases to shortcut this:

alias o='SCREEN=1 exec'
alias p='SCREEN=2 exec'

Use a script to create symlinks for all your hosts given an ~/.ssh/config file like this:

I have a GPG agent that makes it so I only have to enter my private key's password once every few hours. You still have to have some trust in the users of the system because your variable, functions, and aliases that you define could be extracted from RAM. However, I use this mainly for my laptop. If it gets stolen, I don't want someone easily seeing things like: