Skip to content

Instantly share code, notes, and snippets.

@BruceZu
Last active April 16, 2018 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruceZu/a191c8450d745a28bf0c7708ad93d503 to your computer and use it in GitHub Desktop.
Save BruceZu/a191c8450d745a28bf0c7708ad93d503 to your computer and use it in GitHub Desktop.
Command Keyboard Shortcuts hotkeys
Linux
https://www.computerhope.com/ushort.htm
Vim
https://www.maketecheasier.com/vim-keyboard-shortcuts-cheatsheet/
@BruceZu
Copy link
Author

BruceZu commented Apr 7, 2018

Unix and Linux shortcut keys

The Super key is usually the key with the Windows logo

alt+f1 opens the system menu. Then you navigate with the arrow keys and select with the Return key.

alt+f2 opens a command launcher. it doesn't tie up a terminal

alt+f4 closes the focused window.

shift+del permanently deletes a file

alt+mouse grabs a window anywhere

ctrl+alt+l locks the screen.

ctrl+backspace ==deletes an entire word== in many text editors.

ctrl+z is undo, and ctrl+shift+z is redo.

ctrl+a selects all, ctrl+c copies the selection, ctrl+x cuts, and ctrl+v pastes.

shift+arrow keys selects,

crtl+right-left arrow keys moves the cursor a word at a time.

crtl+up-down arrow keys either scrolls up and down a line at a time without moving the cursor, or moves the cursor a line at a time, depending which application you're using.

Unix style of copy-and-paste: selecting text copies it and middle-click pastes it, and the copied text stays in the buffer until it is overwritten with a new selection.

Print Screen button takes a screenshot of your entire desktop

alt+prtsc in GNOME 3 takes a screenshot of the ==active window==. or with shutter as editor

sudo apt-get install shutter

F11 toggles the fullscreen view in a lot of applications, for example Firefox, Chrome, Gedit, and Gimp. But not in most KDE4 applications.

ctrl+double-click selects arbitrary words.

Ctl + Alt + Backspace

when X isn't responding or a program has locked up your desktop and you can't get anything to respond. This combination instantly logs you out of X, taking you back to the login screen.

Ctrl + Alt + Delete

reboot, All data will be lost, so use it wisely.

Alt + Tab

cycle through all open windows

*Ctrl + Alt + F **

It switches to various virtual terminals. The default terminal you're working in is 6 or 7. if you already have a graphical interface going, you'll only be able to work in a text-based terminal window. This is really good for debugging problems with the desktop or killing frozen applications when you don't want to kill X completely.

Alt + Arrow key

If you're using Linux, you probably know about the pager that allows you to have multiple desktops at one time. Instead of having to move your mouse to the edge of a screen, you can hit Alt and either the left or right arrow key to move from one desktop to another.

Screen

Ctrl + - Zoom in

Ctrl + Shit + + Zoom out

Ctrl +0 Zoom normal size

Command Editing Shortcuts

move to end of start

  • Ctrl + a – go to the start of the command line <---
  • Ctrl + e – go to the end of the command line -->
  • Ctrl + xx – move between end of command line and current cursor position (and back again)

move a word

  • Alt + b – move backward one word (or go to start of word the cursor is currently on) <---
  • Alt + f – move forward one word (or go to end of word the cursor is currently on) -->

delete line from cursor

  • Ctrl + k – delete from ==curso==r to the end of the command line -->

  • Ctrl + u – delete from cursor to the start of the command line <---

  • Ctrl + y – ==paste== word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor

  • **Ctrl+Shift+ - ** undo edit

  • **Ctrl+ 7 ** undo edit

delete word from cursor

  • Alt + d – delete to end of ==word== starting at cursor (whole word if cursor is at the beginning of word) ,-->
  • Ctrl + w – delete from before cursor to start of ==word== <---

delete character from cursor

  • Ctrl + d – delete character under the cursor. OR close terminal if not in line -->

  • Ctrl + h – delete character before the cursor <---

upper/lower case

  • Alt + u – uppercase from cursor to end of word
  • Alt + l – lowercase from cursor to end of word
  • Alt + c – capitalize a character at cursor and go to end of word.

swap

  • Alt + t – swap current ==word== with previous

  • Ctrl + t – swap ==character== under cursor with the previous one

Command Recall Shortcuts

  • Ctrl + r – search the history backwards

  • Ctrl + g – escape from history searching mode

    $ cat ~/.inputrc
    "\e[A": history-search-backward
    "\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

    $ tail -2 ~/.bashrc
    bind '"\e[A":history-search-backward'
    bind '"\e[B":history-search-forward'

    so you can use up and down arrows, as expected.

    standard in ZSH?


  • 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 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

  • Ctrl + l – clear the screen

  • Ctrl + s – stops the output to the screen (for long running verbose command) it is a feature of Unix terminals in general that have the “stty ixon” mode established. You can check whether it is on by typing “stty -a” and can turn it off with “stty -ixon.” I leave it turned off in my .profile, because letting the terminal intercept “Ctrl-s” never lets Bash see it, and it is one of Bash's most useful readline features: “Ctrl-s” searches FORWARD through your history, so that after you have started a search with “Ctrl-r” and looked back through a few matching commands, you can hit “Ctrl-s” to start cycling forward back through the matches. You can “Ctrl-r” and “Ctrl-s” to your heart's content until you're sure you've found the version of the command you want. But only if you remember to “stty -ixon”!

  • Ctrl + q – allow output to the screen (if previously stopped using command above)

  • Ctrl + c – terminate the command

  • Ctrl + z – suspend/stop the command This will zombie an application. If you have a process running in a terminal and you want the terminal back but don't want to kill the application, you can hit Ctrl + z to send the process to the background. To get the process back, type fg.

Bash Bang (!) Commands

Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.

  • **!! **– run last command

    $ git log 
    $ !!:s/log/s
    git s 
    $ find . -name fpc-log.txt 
    ./fpc-log.txt
    $ vim $(!!)
    
  • !?

    • !?foo? - to find last command in history with such substring, last ? need if you combine the commands with ":". If you only need to repeat the last command, you can skip the last ?.
    • s/foo/bar/ - search for the substring and replace it with another, but only once.
    • gs/foo/bar/ - search for the substring and replace it with another, but all place
    • :g& repeat search and replace for the whole string.
$ cat fpc-log.txt 
fpc
FpcCollectorAdminMappingServiceImpl
$ grep -rR fpc fpc-log.txt 
fpc
$ !?fpc
grep -rR fpc fpc-log.txt 
fpc
$ !?fpc?:s/fpc/Service/
grep -rR Service fpc-log.txt 
FpcCollectorAdminMappingServiceImpl
$ grep -rR fpc fpc-log.txt 
fpc
$ !?fpc?:s/fpc/Service/:g&
grep -rR Service Service-log.txt 
grep: Service-log.txt: No such file or directory

$ grep -rR fp  fpc-log.txt 
fpc
$ grep -rR fpc fpc-log.txt 
fpc
$ !?fp
grep -rR fpc fpc-log.txt 
fpc
$ !?fp ?
grep -rR fp  fpc-log.txt 
fpc
$ grep -rR fpc fpc-log.txt 
fpc
$ !!:gs/fpc/foo/
grep -rR foo foo-log.txt 
foo
$ grep -rR fpc fpc-log.txt 
fpc
$ !!:s/fpc/foo/
grep -rR foo fpc-log.txt 
  • !git – run the most recent command that starts with ‘git’
  • !git:p – print out the command that !git would run (also adds it as the latest command in the command history)

  • !$ – the last word of the previous command (same as Alt + .)

  • !$:p – print out the word that !$ would substitute


  • !* –gives you all the arguments passed,

  • !*:p – print out what !* would substitute

    $ git log --oneline -5
    $ !$:p
    -5
    
    $ git log --oneline -5
    $ !*:p
    log --oneline -5

  • 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.:

    $ git log --oneline -5 
    $ ^-5^-3
    $ ^--oneline^
  • !:0

    $ git log --oneline -5
    $ !:0
    git
    usage: git [--version] [--help] [-C <path>] [-c name=value]
    ...
    

Vim

**:cq ** cancel an editing session

IDEA

Git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment