Search This Blog

Saturday, May 17, 2014

Linux Bash cheat sheet

I've spend some time googling for bash shortcats using phrases like: bash readline shortcat, copy and paste text to bash clipboard, etc  ... I always forget how to do this, especially when I don't work on Linux for a while.

Below is a list of my favorite (hard to remember) bash shortcats and tricks I like to use.

Bash shortcats

Ctrl + w  Cut the Word before the cursor to the clipboard
Ctrl + y  Paste the last thing to be cut (yank)
Alt + r  Cancel the changes and put back the line as it was in the history (revert).

Bash tricks to speed up typing 
  • How to copy the last command 
  • How to copy and paste the last command output
This one is my favorite because it allows me to refer to a previous command output text without having to copy and paste it with mouse.

# readline function
shell-expand-line (M-C-e)

Example 1:
$ myvar="/etc/passwd"
$ echo $myvar
$ ls $(echo $myvar)

Before you press enter press now (M-C-e) and the line will turn into

ls /etc/passwd-rrr

Example 2:
$ ls -l /etc/passwd
$ echo !!

Before you press enter press now (M-C-e) and the line will turn into

echo ls -l /etc/passwd

Example 3:

$ ls -l /etc/passwd
$ echo $(!!)

Before you press enter press now (M-C-e) and the line will turn into

echo -rw-r--r-- 1 root root 1399 May 17 02:19 /etc/passwd

References

http://ss64.com/bash/syntax-keyboard.html
http://superuser.com/questions/304519/how-to-copy-the-results-from-a-grep-command-to-the-bash-clipboard
http://superuser.com/questions/421463/why-does-ctrl-v-notpaste-in-bash-linux-shell
http://unix.stackexchange.com/questions/15850/how-to-use-keyboard-instead-of-mouse-middle-click-for-copy-paste
http://stackoverflow.com/questions/749544/pipe-to-from-clipboard
https://wiki.archlinux.org/index.php/Keyboard_Shortcuts
http://rtomaszewski.blogspot.co.uk/2013/06/linux-and-bash-cheat-sheet.html



No comments:

Post a Comment