Linux Bash Terminal

Unix command-line shortcuts

A cursor on an empty line is not a prompt, it is a question. The shell does not draw icons and does not hide syntax behind buttons: it waits for you to phrase a thought in words the machine understands. Learning to speak this language is not a "productivity boost", it is a way to stop mediating between yourself and the processor through a mouse.

I am not going to write a "beginner's cheat sheet". You will claw your own way to it, because your hands will get tired of dragging the mouse and the line will grow longer than your patience. There are no badges, no certificates, and no laminated "best practices" from conferences that smell of catering. There is only the language you speak to the machine with — until you learn to speak back. Looking under the hood is the whole secret of "advanced tricks". No magic: just keys invented by people who believed that Ctrl+A is the start of the line, not "select all".

visual cheetsheet

Movement

At first it is awkward. Like hand-soldering a thin joint for the first time, without a jig or a clamp: your fingers tremble, the solder lands crooked. Then they start living on their own. The cursor turns into a little register you move without thinking, and the line becomes a stack where the beginning and the end exist at once, like two sides of an old coin.

Commands Description
ctrl + a Go to the beginning of the line
ctrl + e Go to the end of the line
ctrl + b back 1 character
ctrl + f forward 1 character
alt + f forward 1 word
alt + b back 1 word
ctrl + xx Toggle between the beginning of the line and the current cursor position
ctrl + ] + x If x is any character, move the cursor forward to the next occurrence of x
alt + ctrl + ] + x If x is any character, move the cursor back to the previous occurrence of x.

Editing

And now the line stops being just text. The line is a buffer, the cursor is a pointer, and Ctrl+U and Ctrl+K are like free and kill, only the text is alive. You cut the word before the cursor, paste its tail where the beginning used to be, and no shell framework is needed here: readline has existed longer than most fashionable terminal wrappers and still does its job silently. Ctrl+Z is not "suspend a job" from a textbook, it is an honest signal: the machine is waiting, you went off for data, it will not be offended.

Commands Description
ctrl + d Delete the character under the cursor
ctrl + h Delete the previous character before the cursor
ctrl + u Clear all / cut BEFORE the cursor
ctrl + k Clear all / cut AFTER the cursor
ctrl + w Delete the word BEFORE the cursor
alt + d Delete the word under the cursor
ctrl + y Paste (if you used the previous command to delete)
ctrl + i Autocomplete the command (tab)
ctrl + l Clear
ctrl + c Kill the running process
ctrl + z Suspends the current foreground job. Useful if you want, say, to close the editor and go somewhere for the data you need. You can resume the suspended application with the fg command (bring it to the foreground) or bg (run it in the background).
ctrl + _ Undo the line change
ctrl + t Swap the last two characters before the cursor
esc + t Swap last two words before the cursor
alt + t swap current word with previous
esc + . Insert the last argument of the previous command
esc + _ The same — insert the last argument
alt + [Backspace] delete PREVIOUS word
alt + < Move to the first line in the history
alt + > Move to the end of the input history, i.e., the line currently being entered
alt + ? display the file/folder names in the current path as help
alt + * print all the file/folder names in the current path as parameter
alt + . print the LAST ARGUMENT (ie "vim file1.txt file2.txt" will yield "file2.txt")
alt + c capitalize the first character to end of word starting at cursor (whole word if cursor is at the beginning of word)
alt + u make uppercase from cursor to end of word
alt + l make lowercase from cursor to end of word
alt + n Search forward through command history
alt + p Non-incremental reverse search of history.
alt + r Undo all changes to the line
alt + ctl + e Expand command line.
~[TAB][TAB] List all users
$[TAB][TAB] List all system variables
@[TAB][TAB] List all entries in your /etc/hosts file
[TAB] Auto complete

History

Command history is not a "log" and not an "event journal". It is the machine's memory dug out in reverse, like a disassembler that reads bytes right to left. Ctrl+R — dive deeper, Ctrl+S — surface; !! — replay the past without retyping it, and ^abc^xyz — a little surgery right in the last line. Memory on a machine never asks "are you sure?". It just keeps everything, including the commands you would rather not remember in front of witnesses.

Commands Description
ctrl + r Search backward starting at the current line and moving 'up' through the history as necessary
ctrl + s Search forward starting at the current line and moving 'down' through the history as necessary
ctrl + p Fetch the previous command from the history list, moving back in the list (same as up arrow)
ctrl + n Fetch the next command from the history list, moving forward in the list (same as down arrow)
ctrl + o Execute the command found via Ctrl+r or Ctrl+s
ctrl + g Escape from history searching mode
!! Run PREVIOUS command (ie sudo !!)
!vi Run PREVIOUS command that BEGINS with vi
!vi:p Print previously run command that BEGINS with vi
!n Execute nth command in history
!$ Last argument of last command
!^ First argument of last command
^abc^xyz Replace first occurrence of abc with xyz in last command and execute it

Extra

One day you will realize that this whole set is about the same thing: not spending your life moving the cursor while the tea goes cold somewhere in the kitchen. And along the way you will learn that a Makefile can also give hints, if you know where to poke:

Hint output for a Makefile

The paradox is that the "standard" shell everyone considers a vestige turns out to be more convenient than any fresh terminal superhero. Fashion changes, frameworks die, but Ctrl+A still leads to the beginning of the line. The screen does not go dark — and the cursor keeps blinking, and you type again.