Bash tricks.

It took me some years to start really liking the Linux shell. Even though I know how to type and I knew the commands, it was just tedious to write the full paths, and the full commands every time. The turning point when I really started enjoying was when I learled some Bash tricks. Namely keyboard bindings plus some confiuration options.

  • Ctrl+R to search command history.
  • Alt+. to repeat the last argument
  • Alt+n+. to repeat the nth argument of the previous command.
  • Alt+Backspace to delete the last word.

Plus the Emacs ones:

  • Ctrl+_ to undo.
  • Ctrl+A/E to go to the start/end of the line.
  • Ctrl+F/B to go forward/backward one character.
  • Alt+F/B to go forward/backward one word.
  • Ctrl/Alt+D: delete a character/word forward.
  • Ctrl+P/N to move through command history.
  • Ctrl+K to kill the rest of the line.
  • Copy & paste commands (Ctrl+W, Ctrl+Y, Alt+Y…etc.)

And the configuration options. These go in ~/.inputrc, and are self explanatory:

  • set match-hidden-files off
  • set completion-ignore-case on
  • set show-all-if-ambiguous on
  • set bell-style none
  • set bell-style visible

These go in ~/.bashrc:

  • export HISTSIZE=1000000
  • export HISTFILESIZE=5000000
  • shopt -s checkwinsize
  • shopt -s histappend

The best thing among these keybindings is that they are not specific to Bash: they can be used in all the commands that use the Readline library for input, which, in Linux, ¡are almost all: gdb, python/ipython, sqlite, psql, mysql, bashdb… etc.

With these tricks, I’m probably 10x faster than I used to be before knowing them.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s