π§βπ» Terminal Command Cheat Sheet
A structured, useful, and beginner-friendly article for becoming a command line master.
Written by Fredd
Why should you even care?
A terminal application allows us to browse, read, and enter data into the computer quickly. It may appear antiquated, as it was the only computer interface available until the 1980s. Yet, since working with text-based (i.e. command-line interface (CLI)) terminals is faster than with any GUI operation system (i.e. graphical user interface, such as reading this text in a browser or anything that involves using your mouse and clicking around), it allows you to be more productive and efficient. As you know, efficient solutions are one of the most important goals for engineers.
What is a terminal?
As an example, this is what my terminal looks like:
A terminal is an application that lets us input commands into the computer (i.e. a console), and so lets us interact with the shell. A shell program (like Bash in Linux and Mac OS X, PowerShell for Windows; other popular ones are Fish or Zsh) is a command-line interface (i.e. CLI) program that interprets user commands (e.g., cd Documents/Personal/Photos
= command cd
lets you go into different folders on your computer, such as, in this case, your personal photos folder) from the terminal and executes them.
The shell and the terminal are programs installed by default on all operating systems, but the user can install or remove them. Additionally, the syntax and features of various shells vary. Shells allow us to type in scripts, which are collections of commands/instructions (such as cd
) that a computer can understand and execute.
Simply put, a terminal is software that allows you to input text, and your computer will execute these commands by understanding the shell interpreter.
Interestingly, the program in which the shell will run is the terminal. However, the shell and terminal programs run separately. This implies that you can run any shell on any terminal. In that sense, there is no dependency between the two programs. Bash is typically the default shell that most OSs ship with, yet many advise installing ZSH since it provides a more flexible plugin experience. For example, the default shortcuts for git. I use it on my MacBook Pro as well. Download them here.
Different terminals
Although a default terminal is installed on all operating systems, other choices are available, each with unique features and functionalities. Here is a small list of different operating systems:
Operating System | Terminal Name | Comment |
---|---|---|
macOS | https://iterm2.com/ | iTerm2 is a great alternative to macOS's default terminal. I use it next to my VSCode in-built terminal. |
macOS | https://www.warp.dev/ | Warp is a sleek macOS terminal alternative (i.e. itβs prettier), but you need to sign in and agree to their terms of service, which I find strange. Still, some love it. |
Windows | https://canonical-ubuntu-wsl.readthedocs-hosted.com/en/latest/ | Windows 11 now offers the Windows Subsystem for Linux, allowing Linux systems to run on Windows PCs. |
Linux | https://launchpad.net/terminator | Every Linux distribution emphasizes the terminal and has a decent built-in terminal, but some developers seem pleased by the terminator. |
How do you learn the command lines?
Learning to interact well with the terminal is only done through practice. In contrast to GUI operating systems, where you do not need much prior knowledge to interact with the computer, with a CLI operating system, you need to learn and know the βvocabularyβ/commands for the computer to understand you.
Many videos and articles are out there regarding learning the command lines, yet they are often quite long (I watched some videos for hours), and I believe a personalised cheat sheet is helpful. In this sense, I have listed useful commands below, and you can copy, expand and personalise your own command line cheat sheet. Feel free to share your expanded list with me.
π§° Command Line Cheat Sheet
Important! Generally, play around and have β¨ fun β¨ with the terminal!
βΉοΈ Basic Info
$ indicates that the user (normal user), typically with regular privileges, can input commands.
# indicates that the user is a root user (superuser - dangerous to be always a root user as you can wipe out large data)
# Keyboard shortcut
Control + Shift + (- / +) # Change terminal text size
# Terminology
directories # Means βfoldersβ
files # Means βfilesβ
π File & Directory Operations
ls # List directory contents
ls -a # Show hidden files
ls -la # Long list format with hidden files
ls -l # Detailed list view
pwd # Present working directory
cd [dir] # Change to a directory
cd .. # Go up one directory level
cd # Go to home directory
mkdir [dir] # Make a new directory
touch [file] # Create new file(s)
cp [src] [dst] # Copy file or folder
mv [src] [dst] # Move or rename file/folder
rm [file] # Remove file β
rm * # Remove ALL files ββ
rm -r [dir] # Recursively delete directory βββ
rmdir [dir] # Remove empty directory
π§ Navigation & Pathing
pushd [dir] # Go to dir and save current path
popd # Return to saved path
file [file] # Identify file type
locate [file] # Search for files
π Info & Documentation
whatis [cmd] # Short command description
which [cmd] # Path to a command
man [cmd] # Manual page
history # Show command history
history | less # Pipe history into pager
π Viewing & Editing Files
cat [file] # View file contents
cat [file1 file2] # Merge and display contents
cat > [file] # Overwrite file with input
cat >> [file] # Append to file
more [file] # View one page at a time
less [file] # Paginated file view
nano [file] # Text editor
# Exit keys for more/less/nano
Q # Quit more/less
Control + O # Save in nano
Control + X # Exit nano
π Permissions & Users
chmod +x [file] # Add execute permission
chmod 700 [file] # Full access for owner only
chmod 644 [file] # Owner: RW, Others: R
chmod 755 [dir] # Owner: RWX, Others: RX
sudo [cmd] # Run as superuser
su - [user] # Switch user
id # Show current user ID info
exit # Exit session
π§ You can represent file permissions numerically using a simple system based on addition. Assign a value to each permission type: read (r) is 4, write (w) is 2, and execute (x) is 1. Add the values for the specific permissions you want to grant within each category (owner, group, others). For example, to give the owner full read, write, and execute permissions (rwx), you calculate 4 + 2 + 1 = 7, resulting in the first digit of commands like
chmod 700
.
π System Control & Shortcuts
Control + C # Kill running command
Control + D # End input or exit
Control + L # Clear terminal screen
Cmd + K (macOS) # Clear screen (GUI terminals)
killall [proc] # Kill all instances of a process
π Networking & Ports
lsof -i:8080 # List processes using port 8080
kill -9 [PID] # Kill process using the port
π§ͺ Git & Version Control
# Clone a repo
git clone <url>
# Example:
git clone https://github.com/freddsomm/indiehacker.info
# Commit changes
git add .
git commit -m "FREDD SOMM made a commit."
git push origin main
π Project Setup & Dev Server
# Install dependencies
npm install
# or
yarn install
# or
pnpm install
# Start dev server
npm run dev
# or
yarn dev
# or
pnpm dev
# Stop the server
Control + C
# Run tests
npm test
# or
yarn test
# or
pnpm test
π§ Process & Job Management
ps aux # View all running processes
top # Real-time system monitoring (CPU, RAM)
htop # Enhanced 'top' (requires install)
jobs # List background jobs
bg [job_id] # Resume a job in the background
fg [job_id] # Bring a job to the foreground
kill [PID] # Kill process by ID
π¦ Archives & Compression
tar -czvf archive.tar.gz [folder] # Create a compressed tarball
tar -xzvf archive.tar.gz # Extract a tarball
zip [name].zip [file|folder] # Create zip archive
unzip [name].zip # Extract zip archive
π Networking Tools
ping [host] # Check connectivity
curl [url] # Fetch content from URL
wget [url] # Download files (alternative to curl)
ifconfig # Network interface info (Linux/macOS)
ip a # Modern replacement for ifconfig (Linux)
netstat -tulnp # Show open ports and services
π Disk & Memory Utilities
df -h # Show disk space in human-readable form
du -sh [folder] # Show folder size
free -h # Show memory usage
uptime # System uptime
whoami # Current logged-in user
uname -a # System info
π‘ Scripting & Chaining
# && runs next command only if previous succeeded
npm install && npm run dev
# || runs next command if previous fails
npm install || echo "Install failed"
# Run multiple commands
command1; command2; command3
π§Ή Disk Cleanup
sudo apt autoremove # Remove unused packages (Debian/Ubuntu)
sudo apt clean # Clean up cached files
brew cleanup # Homebrew cleanup (macOS)
π Clipboard & Output Redirection
echo "Hello" > file.txt # Write to file (overwrite)
echo "Again" >> file.txt # Append to file
cat file.txt | pbcopy # Copy file contents (macOS)
π§ͺ Extras
code . # Open VS Code from terminal
pbcopy # Copy terminal output to clipboard (macOS)
pbpaste # Paste clipboard content (macOS)
ls -al / > fileName.txt # Save directory list to file
Conclusion
Terminals may seem antiquated initially, but they offer unparalleled speed and efficiency in computer interaction, making them indispensable tools for productive (software) engineers. As engineers strive for efficient solutions, mastering the command-line interface becomes crucial for communicating well with your computer.
I hope you found this article and, especially, the cheat sheet helpful. I would love to hear your feedback on it.
Happy hacking! π