Menu

Terminal Cheat Sheet

Last updated

Move around the filesystem and see where you are.

CommandWhat it does
pwdPrint the current working directory
lsList files in the current directory
ls -laList all files (including hidden) with details
cd dirChange into dir
cd ..Go up one directory
cd ~Go to your home directory
cd -Go back to the previous directory
treeShow the directory tree (if installed)

Files & directories

Create, copy, move, and delete files and folders.

CommandWhat it does
touch file.txtCreate an empty file (or update its timestamp)
mkdir dirCreate a directory
mkdir -p a/b/cCreate nested directories, no error if they exist
cp src dstCopy a file
cp -r src dstCopy a directory recursively
mv src dstMove or rename a file
rm fileDelete a file
rm -r dirDelete a directory and its contents
rm -rf dirForce-delete recursively (no prompt - careful)

Viewing files

Print or page through file contents.

CommandWhat it does
cat filePrint the whole file
less fileScroll through a file page by page (q to quit)
head fileShow the first 10 lines
head -n 20 fileShow the first 20 lines
tail fileShow the last 10 lines
tail -f logFollow a file as new lines are appended
wc -l fileCount the number of lines

Searching

Find files by name and search inside their contents.

CommandWhat it does
grep "text" fileFind lines matching text in a file
grep -r "text" .Search recursively from the current directory
grep -i "text" fileCase-insensitive search
grep -n "text" fileShow matching line numbers
find . -name "*.js"Find files by name pattern
find . -type dFind only directories
find . -size +1MFind files larger than 1 MB

Pipes & redirection

Combine commands and control where their input and output go.

CommandWhat it does
cmd1 | cmd2Pipe the output of cmd1 into cmd2
cmd > fileRedirect output to a file (overwrites it)
cmd >> fileAppend output to a file
cmd < fileRead input from a file
cmd 2> errors.txtRedirect only error output (stderr)
cmd > out.txt 2>&1Send both output and errors to one file
cmd | tee filePrint output and write it to a file at once
ls | grep .txtExample: list files, keep only the .txt ones

Permissions

Change who can read, write, or run a file.

CommandWhat it does
ls -lShow permissions, owner, and size of each file
chmod +x script.shMake a file executable
chmod 644 fileSet rw-r--r-- (owner writes, others read)
chmod 755 fileSet rwxr-xr-x (owner all, others read/run)
chown user fileChange the file's owner
chown user:group fileChange owner and group
sudo cmdRun a command as the superuser

Process control

Inspect, pause, and stop running programs.

CommandWhat it does
ps auxList all running processes
topLive view of processes and resource usage
kill PIDSend a terminate signal to a process by ID
kill -9 PIDForce-kill a process
cmd &Run a command in the background
jobsList background jobs in this shell
fgBring a background job to the foreground
bgResume a suspended job in the background

History & shortcuts

Recall past commands and control the current one.

CommandWhat it does
historyShow recently run commands
!!Re-run the previous command
!42Re-run command number 42 from history
Ctrl+RSearch backward through command history
Ctrl+CCancel the running command
Ctrl+ZSuspend the running command
Ctrl+LClear the screen (same as clear)
Ctrl+A / Ctrl+EJump to start / end of the line

Environment & misc

Variables, locating commands, and getting help.

CommandWhat it does
echo $HOMEPrint an environment variable
export VAR=valueSet an environment variable for this session
which pythonShow the full path of a command
man lsOpen the manual page for a command
ls --helpShow quick usage for a command
alias ll="ls -la"Create a shortcut for a command
clearClear the terminal screen

Every command you reach for at the prompt, on one page. This terminal cheat sheet is a quick reference for the interactive shell - moving around the filesystem, working with files, wiring commands together with pipes and redirection, and managing running processes.

The commands here are standard on bash and zsh, so they work the same on Linux and macOS. Copy what you need, or try them live in the terminal playground - a real shell in your browser, nothing to install.

Terminal cheat sheet FAQ

Is this terminal cheat sheet free?
Yes. This terminal cheat sheet is completely free, with no sign-up required. Bookmark it and come back whenever you need to look up a command, flag, or shortcut.
What shell is this cheat sheet for - bash or zsh?
Both. The commands here are part of the standard Unix toolset and behave the same in bash and zsh, which are the default shells on Linux and macOS. zsh adds extra features like smarter tab completion, but everything on this page works in either shell, and most of it also works in other POSIX shells.
What does the pipe | do?
A pipe sends the output of one command straight into the next command as its input, so you can chain small tools into a pipeline. For example, ls | grep .txt lists files and then filters that list to only the names containing .txt - no temporary file needed.
Can I practice these terminal commands online?
Yes. Open the terminal playground to run any command from this cheat sheet in a real shell in your browser - nothing to install. When you want structure, Coddy's free interactive terminal course walks you from navigation to pipes and process control step by step.
Is this cheat sheet good for beginners?
Yes. It is organized from the most common tasks (navigation and files) down to advanced ones (process control and environment variables), so you can use the top sections on day one and grow into the rest.
Coddy programming languages illustration

Learn Terminal with Coddy

GET STARTED