Bash Shortcuts
* Ctrl+R Incremental search forward, in your command-line history.
- Ctrl+S Incremental search backwards, in your command-line history.
- Ctrl+J and Ctrl+G: These useful commands abandon an incremental search, either with the line found, or with the original line, respectively.
- Alt-. or ESC then . Both insert the final argument to the last command at the cursor point. Useful when moving files around and editing them.
- Ctrl+A Move to the beginning of the command line.
- Ctrl+E Move to the end of the command line.
- Alt+C+Y Insert the first argument to the previous command at the cursor point. If you want the nth argument, hit Alt+N beforehand. So Alt+2 Alt+C+Y will give you the second argument to the previous command. That's a lot of keys to remember, but it's useful once in a while.
- Ctrl+U Deletes from the cursor to the beginning of the line. Also works when entering passwords, so it's useful when you get stuck halfway and forget where you've got to. If you want to use the line again, use C+Y.
- Ctrl+T and Alt+T transpose characters and words respectively. Pulls the character/word behind the cursor over the character/word at the cursor. Unfortunately, in at least some terminals (such as Gnome Terminal) Alt+T is overridden, so this may not work for you.
- Ctrl+W and Alt+backspace Both delete the word behind the cursor; but Ctrl+W uses whitespace as a boundary, whereas M+backspace uses non-alphanumeric characters. So if you have file.txt and hit Ctrl+W, you'll delete the lot; Alt+backspace will leave you with file.. (This also works with underscores.)
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'