Skip to content

Instantly share code, notes, and snippets.

@asahicantu
Last active February 1, 2024 09:57
Show Gist options
  • Save asahicantu/e2be6bebffdd6add9dd8c9c1defacbfb to your computer and use it in GitHub Desktop.
Save asahicantu/e2be6bebffdd6add9dd8c9c1defacbfb to your computer and use it in GitHub Desktop.
Linux commands

Bash keyboard shortcuts

ALT key shortcuts

ALT+A – Jump to the beginning of a line. ALT+B – Move one character before the cursor. ALT+C – Suspends the running command/process. ALT+D – Closes the empty Terminal. ALT+F – Move forward one character. ALT+T – Swaps the last two words. ALT+U – Capitalize all characters in a word after the cursor. ALT+L – Uncaptalize all characters in a word after the cursor. ALT+R – Undo any changes to a command that you have brought from the history if you’ve edited it. ALT+. – Use the last word of the previous command.

CTRL key shortcuts

CTRL+H – Delete the characters before the cursor, same as BACKSPACE. CTRL+K – Delete all characters after the cursor. CTRL+D – Delete one character backward. CTRL+U – Delete all characters before the cursor. CTRL+W – Delete the words before the cursor.

CTRL+A – Quickly move to the beginning of the line. CTRL+B – To move backward one character. CTRL+C – Stop the currently running command

CTRL+E – Move to the end of the line. CTRL+F – Move forward one character. CTRL+G – Leave the history searching mode without running the command.

CTRL+J – Same as ENTER/RETURN key.

CTRL+L – Clears the screen and redisplay the line. CTRL+M – Same as CTRL+J or RETURN. CTRL+N – Display next line in the command history. Or using the DOWN arrow. CTRL+O – Run the command that you found using reverse search i.e CTRL+R. CTRL+P – Displays the previous line in the command history. Or using the UP arrow. CTRL+R – Searches the history backward (Reverse search). CTRL+S – Searches the history forward. CTRL+T – Swaps the last two characters. CTRL+V – Makes the next character typed verbatim. CTRL+X – Lists the possible filename completions of the current word. CTRL+XX – Jump to start point of the line and back to the current cursor position. CTRL+Y – Retrieves the last item that you deleted or cut. Opposite of CTRL+W. CTRL+Z – Stops the current command. CTRL+[ – Equivalent to ESC key.

Miscellaneous Bash Keyboard Shortcuts

!! – Repeats the last command. ESC+t – Swaps the last two words. Tab – Auto-complete files and folder names

# Use of Bang !
grep <word> <file>
cat <file>
# It will call the closest command found in history
!grep
# Repeats the last command
!!
# Repeats command by history number
# !5
cat history.html
# repeats the path from previous command
cat !$
# reuse the arguments of a previous commands
cat !*
# or limit the amount of arguments
cat !4
# CTRL + R to cycle trhough history
# VIM Basics
## Working With Files
```bash
vim <filename> Open a file in Vim
:w Save a file
:q Quit a file
:wq Save and quit
:q! Quit without saving
ZZ Save (if modified) and exit
:w <filename> Save a copy as filename
```
## Vim Modes
```bash
Esc Normal mode. Default starting mode.
i Insert mode. Esc to normal mode.
v Visual mode. Esc to normal mode.
: Command-line mode. Esc to normal mode.
```
## Navigating
Arrow keys Move around (or h,j,k,l---left, down, up, right)
```bash
$ End of line
0 Beginning of line
Ctrl + u Half-page up
Ctrl + d Half-page down
b Backwards a word
w Forward a word
G Bottom of file
gg Top of file(or 1G)
:set number Display line numbering
:set nonumber Hide line numbering
:5 Go to line 5
```
## Vimdiff
```bash
vimdiff <file1> <file2> Compare file1 (left) and file2 (right)
]c Go to next diff
[c Go to previous diff
dp Diff put
do Diff get
:diffupdate Rescan files for changes
Ctrl + ww Switch between split windows
```
## Editing
```bash
i Insert mode. Esc to normal mode.
o Insert new line below
O Insert new line above
I Insert at beginning of line
A Insert (append) at end of line
x Delete character
dd Delete line
2dd Delete two lines
5x Delete 5 characters
dG Delete from cursor to end of file
d$ Delete from cursor to end of line
dgg Delete from cursor to beginning of file
yy Yank (copy) a line
```
## Visual Mode
```bash
v Enter Visual mode
Arrow keys Highlight text in Visual mode
y Yank (copy) selection
c Change (cut) selection
d Delete selection
p Paste selection. Esc to enter normal mode to paste.
Esc Enter normal mode
```
## Build Efficiency
```bash
u Undo (from normal mode)
Ctrl + r Redo (from normal mode)
/searchterm Search for searchterm. Add \c for case insensitive.
n Next instance of searchterm
N Previous instance of searchterm
:%s/replaceme/withme/g Replace "replaceme" with "withme" in the entire file
:%s/replaceme/withme/gc Replace "replaceme" with "withme" and prompt
:set paste Disable auto-indent upon paste
:set nopaste Re-enable auto-indent upon paste
?searchterm Search backwards in file for searchterm
. Repeat last change
q: Easter egg? pull history mode
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment