These are some of the shortcuts that i use ...
Command Editing Shortcuts
- Ctrl + a – go to the start of the command line
- Ctrl + e – go to the end of the command line
- Ctrl + k – delete from cursor to the end of the command line
- Ctrl + u – delete from cursor to the start of the command line
- Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
- Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Command Recall Shortcuts
- Ctrl + r – search the history backwards
- Ctrl + g – escape from history searching mode
- Ctrl + p – previous command in history (i.e. walk back through the command history)
- Ctrl + n – next command in history (i.e. walk forward through the command history)
- Alt + . – use the last word of the previous command
- Ctrl + o - This command is my favourite. If you hit CTRL+o after picking a command from your history, the command is executed, and the next command from history is prepared on the prompt.
Command Control Shortcuts [Not a Bash Feature]
- Ctrl + l – clear the screen
- Ctrl + s – stops the output to the screen (for long running verbose command)
- Ctrl + q – allow output to the screen (if previously stopped using command above)
- Ctrl + c – terminate the command
- Ctrl + z – suspend/stop the command
Bash Bang (!) Commands
- !! - run last command
- !blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
- !$ – the last word of the previous command (same as Alt + .)
- !* – all of the previous command except for the first word (e.g. if you type ‘ls foo foo/bar foo/bar/foo‘, then !* would give you ‘foo foo/bar foo/bar/foo‘)
- ^^ - If you type a command and run it, you can re-run the same command but substitute a piece of text for another piece of text using ^^ (e.g.: if you run 'ls this/is/cool/stuff' and if you do '^cool^geek' then it will run 'ls this/is/geek/stuff'. It replaces only the first occurance)
- !!:gs/search/replace/ - It is same as previous except it replaces all occurance
Tricks with ~/.inputrc
- Put this in your ~/.inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
"\C-p": history-search-backward
"\C-n": history-search-forward
"\e[B": history-search-forward
"\C-p": history-search-backward
"\C-n": history-search-forward
Type something, then pressing Ctrl-p(or Ctrl-n) will initiate the search in the history with the already typed text as prefix
No comments:
Post a Comment