Tuesday, November 15, 2005

Bash Hotkeys

Bash provides many hot keys to ease use. Like
ctrl-l -- clear screen
ctrl-r -- does a search in the previously given commands
ctrl-u -- clears the typing before the hotkey.
ctrl-a -- takes you to the begining of the command you are currently typing.
ctrl-e -- takes you to the end of the command you are currently typing in.
esc-b -- takes you back by one word while typing a command.
ctrl-c -- kills the current command or process.
ctrl-d -- kills the shell.
ctrl-h -- deletes one letter at a time from the command you are typing in.
ctrl-z -- puts the currently running process in background, the process
can be brought back to run state by using fg command.
esc-p -- like ctrl-r lets you search through the previously given commands.
esc-. -- gives the last command you typed.

More Bash tips and tricks

Dominic wrote a coolsolution about Equivalents of DOS Commands

Searching the Past

  • There are several bad ways of finding previous lines from history
  • Many people go for pressing Up lots (and lots)
    • A tad inefficient, perhaps
  • Cannier folk know that Ctrl+R searches previous lines
    • But Ctrl+R zip Esc does not find the last zip command it also matches any line that copied, deleted, unzipped, or did anything else with a zip file
  • Those of a gambling bent can chance ! and a command name
    • Irritating when !gv opens gvim instead of gv

Sane Incremental Searching

  • Bash can cycle through lines starting in a particular way
  • Just type in a few characters then press Up
    • Do not need to press Up so many times
    • Do not see lines that merely contain those letters
    • Do not have to chance executing the wrong line

Specifying Directories

  • Bash can help with specifying directory names
  • cd - changes back to the previous directory
    • Handy if you forgot to pushd
  • In general ~- is the previous directory
    • Useful for working with files in 2 different directories