Linux Cheatsheet

Basics

Use this Linux reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Shell Basics

whoami          # current user
hostname        # machine name
date            # current date/time
uptime          # system uptime + load averages
uname -a        # kernel/OS info
echo $SHELL     # active shell path
history         # command history
!!              # re-run last command
!42             # re-run history entry 42
ctrl+r          # reverse search history

Use Linux With Online Code Editors

When you run code online, the browser editor usually hides the operating system, but the same Linux ideas still explain paths, stdin/stdout, environment variables, files, and process output. Keep this reference next to the online compiler, Python online compiler, JavaScript playground, or C++ online compiler when moving between browser practice and a local terminal.

pwd                 # where this command is running
ls                  # files available to the program
cat input.txt       # inspect redirected input
node app.js         # run JavaScript locally after browser practice
python3 main.py     # run Python locally after online compiler practice
g++ main.cpp -o app # compile C++ locally after C++ online compiler practice

Variables and Environment

VAR=value           # set local variable
export VAR=value    # export to environment
echo $VAR           # read variable
env                 # all exported variables
printenv PATH       # print one variable
unset VAR           # remove variable
SyntaxMeaning
$VARvalue of variable
${VAR:-default}value or default if unset
${VAR:=default}value or set-and-use default
${#VAR}length of string
$(command)command substitution
` command `command substitution (older)

Aliases and Functions

alias ll='ls -lhA'          # define alias
alias                       # list all aliases
unalias ll                  # remove alias
type ll                     # show alias/function/builtin

myfunc() {
  echo "Hello, $1"
}
myfunc World

Put aliases and functions in ~/.bashrc (Bash) or ~/.zshrc (Zsh) to persist them.

Quoting Rules

QuoteBehavior
'single'literal — no expansions
"double"expands $VAR, $(cmd), ` cmd `
\charescape one character
$'...'ANSI-C escapes (\n, \t, etc.)

Keyboard Shortcuts (Readline)

KeyAction
ctrl+amove to start of line
ctrl+emove to end of line
ctrl+kcut from cursor to end
ctrl+ucut from cursor to start
ctrl+ypaste (yank)
ctrl+wcut previous word
ctrl+lclear screen
ctrl+ccancel current command
ctrl+zsuspend to background
ctrl+dEOF / logout
tabautocomplete

Getting Help

man ls              # full manual page
man -k keyword      # search man pages (also: apropos keyword)
info coreutils      # GNU info pages
ls --help           # short built-in help
type -a cd          # what is this command?
which python3       # path of executable