# line editing shortcuts
Ctrl+A move cursor to the beginning of the line
Ctrl+E move cursor to the end of the line
Ctrl+U cut everything before the cursor
Ctrl+K cut everything after the cursor
Ctrl+W cut the word before the cursor
Ctrl+Y paste (yank) the last cut text
Ctrl+L clear the screen (same as clear)
Ctrl+R reverse search through command history
# history tricks
!! repeat the last command — e.g. sudo !!
!$ last argument of the previous command
!* all arguments of the previous command
^old^new rerun previous command, replacing old with new
history | grep ssh search your command history
# built-ins
export VAR=value set an environment variable for child processes
source ~/.bashrc run a script in the current shell (also: . ~/.bashrc)
type ls tell whether a command is a builtin, alias, function or binary
jobs list background jobs in the current shell
fg bring the most recent background job to the foreground
bg resume a stopped job in the background
command sleep 100 & run a command in the background with &
kill %1 kill background job number 1
read -p "Name: " name read user input into a variable
# expansion
mkdir -p src/{js,css,img} brace expansion — creates three directories at once
cp file.txt{,.bak} quick backup: expands to cp file.txt file.txt.bak
echo ${VAR:-default} use a default value if VAR is unset
echo $(date) command substitution — insert output of a command