Bash Shortcuts

* Ctrl+R Incremental search forward, in your command-line history.

Background a running job

You're running a script, command, whatever..
You don't expect it to take long, now 5pm has rolled around and you're ready to go home…
Wait, it's still running…
You forgot to NOHUP it before running it…
Suspend it, send it to the background, then disown it…
The ouput won't go anywhere, but at least the command will keep running…

# ^Z 
# bg 
# jobs

now, assuming you're trying to detach job numbered 1

# disown %1

or

# disown -a && exit

BASH Autocompletion

Add to your .profile to have BASH TAB Autocompletion for ssh/ping

# cat ~/.profile
complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh
complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ping

SU to user

Change user, assume environment, stay in current dir (Instead of just 'su - user' adding another hyphen keeps you in your original directory)

# su -- user

History grep

Place this in your .bash_profile and you can use it two different ways.

h() { if [ -z "$1" ]; then history; else history | grep "$@"; fi; }

If you issue 'h' on its own, then it acts like the history command

# h

If you issue

h ping

Then it will display all the history with the word 'ping'