The most common thing that you have to know when you start to manage Linux-based servers are CLI and /bin/bash that the most spread shell . Anyway, there is a huge amount of task and routine actions that you will perform in a shell. Cause it faster, easier, more accurately that in GUI or Web interfaces. Eventually, the speed of performing the task depends on speed and experience work in shell. So, I want to introduce you some shortcuts that can be useful in your common practice. Some of them you may know, but I hope a couple of them will be pretty new for you.

Tab-using

  • Tab Try to complete command or filename
  • Tab-Tab Shows possible additions to current command/filename and add in current line commom part
  • * + Tab-Tab Shows subdirectories exclude hidden
  • ~ + Tab-Tab Shows all users from /etc/passwd. Btw you can use ~username as username homedir. For example ll ~www-data is exactly the same ll /var/www
  • = + Tab-Tab Shows listing of current directory
  • Alt+? Shows all possible additions to this command (similar as Tab-Tab but just shows)
  • Alt+* Inserts all possible additions to this command in line or all files in current directory
  • Alt+/ Try to complete filename (same as Tab but just only for filenames)

Moving the cursor

  • Ctrl+A Go to the beginning of the line you are currently typing on (as End key)
  • Ctrl+E Go to the end of the line you are currently typing on (as Home key)
  • Ctrl+XX Toggle between the start of line and current cursor position
  • Ctrl+F Forward (right) one character
  • Ctrl+B Back (left) one character
  • Alt+F Forward one word
  • Alt+B Backward one word

Editing

  • Ctrl+L Clears the Screen, similar to the clear command
  • Ctrl+U Cut/delete the line before the cursor position. If you are at the end of the line, clears the entire line.
  • Ctrl+K Cut/delete the line after the cursor
  • Ctrl+W Cut/delete the word before the cursor
  • Ctrl+H Delete character before the cursor. Same as backspace
  • Ctrl+Y Paste the last thing to be cut (yank)
  • Alt+Y (After the Ctrl+Y) Loop through previously cut things
  • Ctrl+T Swap the last two characters before the cursor (suod_ may happens with anyone)
  • Esc+T/Alt+T Swap the last two words before the cursor (perfect for systemctl nginx reload)
  • Alt+U UPPER capitalize every character from the cursor to the end of the current word.
  • Alt+L Lower the case of every character from the cursor to the end of the current word.
  • Alt+C Capitalize the character under the cursor and move to the end of the word.
  • Alt+R Cancel the changes and put back the line as it was in the history (revert).
  • Ctrl+- Undo
  • Ctrl+X+Ctrl+E Open $EDITOR for editing current string. After saving it goes to execute.

History

  • Ctrl+R Searches through previously used commands (no need history | grep foo anymore). Repeat Ctrl + R for loop through results.
  • Ctrl+P Previous command (Up arrow)
  • Ctrl+N Next command (Down arrow)
  • Ctrl+O Execute the command found via Ctrl+R
  • Ctrl+G Escape from history searching mode
  • !! Substitute the last command
  • !foo Run the last command starting with foo
  • !foo:p Print the last command starting with foo
  • !$/Alt+. Last argument of the previous command
  • !* All arguments of the previous command
  • ^foo^bar Run the previous command, replacing abc with def

Processes

  • Ctrl+C Kill whatever you are running
  • Ctrl+D Exit the current shell
  • Ctrl+Z Puts whatever you are running into a suspended background process. fg restores it.
  • Ctrl+S Stop output to the screen (for long-running verbose commands). Then you can use PgUp/PgDn for navigation
  • Ctrl+Q Allow output to the screen (if previously stopped using Ctrl+S)

All of these commands work in default Emacs-mode. You can switch it to Vi-mode and use all the power of Vi in your command line. More details about Vi(m) shortcuts and commands ahead. Stay tuned.

Set Vi Mode in bash: set -o vi

Set Emacs Mode in bash: set -o emacs