Linux Commands & Keyboard Shortcuts Cheat Sheet


updated

Just a quick cheat sheet of basic and slightly less basic Linux commands, as well as handy keyboard shortcuts, that I maintain for myself since I can't always remember them all.

Sections

  1. Commands
  2. Basic Usage Examples
  3. Advanced Commands & Usage
  4. Handy Keyboard Shortcuts
  5. Reference

Commands

CommandEffect
manopen “manual page” for specified command/utility (e.g. man ls opens ls command’s man page)
clearclears the terminal screen
lslist contents of directory (use -a to show hidden files, -l to show in long list format)
cdchange present working directory (cd .. to move back one directory)
mkdircreate new directory, multiple directories separated by spaces
touchcreate new file(s)
cpcopy a file
mvmove a file, also the way to rename files
rmdelete files(s)
rm -rfdelete recursively, necessary for deleting directories and all contents in them
duoutput sizes of files within a directory recursively (use -m for MiB or -g for GiB)
catoutput all lines of a file onto terminal
headoutputs first 10 lines of a file (use -n followed by a number to display different amount)
tailoutputs last 10 lines of a file (use -n followed by a number to display different amount)
lessopens file in its own “page” similar to man, rather than outputting to terminal like cat
!!repeat last command
dateoutput system date
uptimeoutput system uptime
whoamioutput current user
whichoutput path of a command, if present (e.g. which nano shows path of nano
findsearch for files/directories matching a particular pattern (see usage examples below)
historyoutput history of commands used, numbered in order
&&append between commands to run them in order (e.g. apt update && apt upgrade)
dfoutput used and available space on mounted disks in bytes (-h to show MiB, GiB, TiB)
psoutput of user-initiated processes and their process IDs
topopens separate page showing real-time information on running processes
kill {PID}terminate a running process, must specify the PID
rebootreboots the machine (may require sudo)
shutdownshuts down the machine (may require sudo)
sudoappend prior to a command to use with elevated privileges (e.g. sudo shutdown)

Basic Usage Examples

CommandEffect
ls /path/to/directorylist files in a specific directory
cd /path/to/other-directorychange from current working directory to another
mkdir new-directory-namecreate a new directory within current working directory
touch filenamecreate new files, can specify file extension
cp file /path/to/directory/filecopy a file to another directory
mv file /path/to/new-filenamemove (or rename) a file, leaves no copy behind
rm -rf /path/to/directorydelete a directory and it’s contents
find /etc -name hostsshows any files in /etc with hosts in filename
find /etc -type d -name '*.confshows any directories (d) in /etc with .conf in filename

Advanced Commands & Usage

CommandEffect
ln file1 file2creates a hard link between files, updates to either file syncs with the other
ln -s file1 file2creates a symbolic link between files, but if original is deleted, symlinked file no longer works
sadduser maryadd new user (must be done by root or with sudo)
usermod -aG sudo marygive a user sudo powers (must be done by root or with sudo)
su maryswitch to user (keep current environment variables)
su - maryswitch to user (new environment when using -)
su mary passwdchange user password (must be done by root or with sudo)
ssh-keygengenerate a basic SSH key pair

Handy Keyboard Shortcuts

Key CombinationEffect
Ctrl + Cinterupt/terminate current process
Ctrl + Ago to start of line
Ctrl + Ego to end of line
Ctrl + Udelete entire line