Linux/Terminal Commands Cheat Sheet 2026 — Essential Commands

Bookmark this page. Use Ctrl+F (or Cmd+F on Mac) to find what you need. This cheat sheet covers essential terminal commands for macOS and Linux. Last updated: March 2026 Navigation Command Description pwd Print current directory ls List files ls -la List all files with details (including hidden) ls -lh List with human-readable sizes cd /path Change directory cd ~ Go to home directory cd .. Go up one directory cd - Go to previous directory tree Show directory tree (install: brew install tree) tree -L 2 Tree with max depth 2 Files and Directories Command Description touch file.txt Create empty file mkdir mydir Create directory mkdir -p a/b/c Create nested directories cp file.txt copy.txt Copy file cp -r dir/ newdir/ Copy directory recursively mv file.txt newname.txt Rename/move file rm file.txt Delete file rm -r dir/ Delete directory recursively rm -rf dir/ Force delete (no confirmation) ln -s target link Create symbolic link cat file.txt Print file contents head -20 file.txt First 20 lines tail -20 file.txt Last 20 lines tail -f file.log Follow file in real-time (logs) less file.txt Paginated viewer (q to quit) wc -l file.txt Count lines wc -w file.txt Count words diff file1 file2 Compare two files stat file.txt File details (size, dates, permissions) Searching Command Description grep "text" file.txt Search for text in file grep -r "text" dir/ Search recursively in directory grep -i "text" file.txt Case-insensitive search grep -n "text" file.txt Show line numbers grep -c "text" file.txt Count matches grep -v "text" file.txt Show lines NOT matching find . -name "*.txt" Find files by name find . -type d -name "src" Find directories by name find . -size +10M Find files larger than 10MB find . -mtime -7 Files modified in last 7 days which python Find where a command lives locate file.txt Fast file search (uses index) Pipes and Redirection # Pipe — send output of one command to another ls -la | grep ".txt" cat file.txt | sort | uniq ps aux | grep node # Redirect output to file echo "hello" > file.txt # overwrite echo "world" >> file.txt # append # Redirect errors command 2> errors.log # stderr to file command > output.log 2>&1 # stdout + stderr to file command &> all.log # same (bash shorthand) # /dev/null — discard output command > /dev/null 2>&1 # silence everything cmd1 | cmd2 pipe: stdout of cmd1 → stdin of cmd2 cmd > file redirect stdout to file (overwrite) cmd >> file redirect stdout to file (append) cmd 2> file redirect stderr to file cmd < file use file as stdin Permissions -rwxr-xr-- 1 alex staff 4096 Mar 15 file.txt │├─┤├─┤├─┤ │ │ │ │ │ │ │ └── Others: read only │ │ └───── Group: read + execute │ └───────── Owner: read + write + execute └─────────── File type (- = file, d = directory, l = link) Command Description chmod 755 file rwxr-xr-x (owner all, group/others read+exec) chmod 644 file rw-r–r– (owner read+write, others read) chmod +x script.sh Add execute permission chmod -w file.txt Remove write permission chown user:group file Change owner and group chown -R user dir/ Change owner recursively Number Permission 7 rwx (read + write + execute) 6 rw- (read + write) 5 r-x (read + execute) 4 r– (read only) 0 — (no permission) Processes Command Description ps aux List all processes ps aux | grep node Find a specific process top Live process monitor htop Better process monitor (install separately) kill <pid> Send SIGTERM (graceful stop) kill -9 <pid> Send SIGKILL (force stop) killall node Kill all processes by name lsof -i :3000 Find what is using port 3000 jobs List background jobs bg Resume job in background fg Bring job to foreground command & Run command in background nohup command & Run and keep running after logout Disk and System Command Description df -h Disk usage (human-readable) du -sh dir/ Directory size du -sh * | sort -rh Largest items in current dir free -h Memory usage (Linux) uname -a System info hostname Machine name uptime System uptime and load date Current date/time cal Calendar Networking Command Description curl https://example.com Fetch a URL curl -o file.html https://example.com Download to file curl -X POST -d '{"key":"value"}' -H "Content-Type: application/json" url POST JSON wget https://example.com/file.zip Download a file ping example.com Test connectivity ifconfig / ip addr Show network interfaces netstat -tlnp / ss -tlnp Show listening ports ssh user@host Connect via SSH scp file.txt user@host:/path Copy file to remote scp user@host:/path/file.txt . Copy file from remote Archives Command Description tar -czf archive.tar.gz dir/ Create gzip archive tar -xzf archive.tar.gz Extract gzip archive tar -xzf archive.tar.gz -C /dest Extract to directory zip -r archive.zip dir/ Create zip archive unzip archive.zip Extract zip Text Processing # Sort lines sort file.txt sort -r file.txt # reverse sort -n file.txt # numeric sort sort -u file.txt # unique only # Unique lines (file must be sorted first) sort file.txt | uniq sort file.txt | uniq -c # count occurrences # Cut columns cut -d',' -f1,3 data.csv # columns 1 and 3 (comma delimiter) # Replace text sed 's/old/new/g' file.txt # replace all occurrences sed -i 's/old/new/g' file.txt # in-place edit (Linux) sed -i '' 's/old/new/g' file.txt # in-place edit (macOS — needs empty '') # Print specific lines awk '{print $1, $3}' file.txt # columns 1 and 3 (space delimiter) awk -F',' '{print $1}' data.csv # with custom delimiter # Count and summarize cat access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10 # → top 10 IP addresses in an access log Keyboard Shortcuts (Terminal) Shortcut Action Ctrl+C Cancel current command Ctrl+D Exit shell / close terminal Ctrl+Z Suspend current process Ctrl+L Clear screen Ctrl+R Search command history Ctrl+A Move cursor to start of line Ctrl+E Move cursor to end of line Ctrl+W Delete word before cursor Ctrl+U Delete entire line before cursor Tab Auto-complete file/command name !! Repeat last command !$ Last argument of previous command Environment Variables echo $HOME # print variable export MY_VAR="value" # set for current session echo 'export MY_VAR="value"' >> ~/.zshrc # permanent (Zsh) echo 'export MY_VAR="value"' >> ~/.bashrc # permanent (Bash) env # list all env variables printenv PATH # print specific variable Common Mistakes rm -rf / or rm -rf * — There is no recycle bin in the terminal. Deleted files are gone. Always double-check your path before running rm -rf. Use ls first to preview what will be deleted. ...

July 14, 2026 · 6 min

DevTools Capstone: Building and Deploying a Full-Stack App with Git, Docker, and SQL

This is the final article in the DevTools series. In the previous 17 articles, you learned Git, Docker, and SQL separately. Now you will use all three together to build and deploy a real project. We will build a simple task management API with a PostgreSQL database. You will set up a Git repository with feature branches, write the API, Dockerize everything, add a CI/CD pipeline with GitHub Actions, and deploy it to a server. ...

June 16, 2026 · 15 min

SQL Tutorial #7: PostgreSQL Setup — A Real Database for Real Projects

You have been practicing with SQLite. It is great for learning. But for real projects, you need a real database. PostgreSQL (often called “Postgres”) is the most popular open-source relational database. It is used by companies of all sizes, from startups to enterprises. In this article, you will set it up, connect to it, and learn its unique features. In the previous article, you learned about indexes and performance. Now you will put everything together with a production-ready database. ...

June 16, 2026 · 12 min

SQL Tutorial #6: Indexes and Performance — Making Queries Fast

Your queries work. But they are slow. A simple SELECT takes seconds instead of milliseconds. On a table with millions of rows, it could take minutes. The fix is almost always the same: add an index. In the previous article, you learned about window functions. Now you will learn how to make all your queries run fast. What Is an Index? Think of a book’s index at the back. If you want to find “window functions” in a 500-page book, you have two options: ...

June 16, 2026 · 10 min

SQL Tutorial #5: Window Functions — Analytics Without GROUP BY

GROUP BY is great for summaries. But it collapses your rows. You get one row per group. What if you want the summary and the individual rows at the same time? That is what window functions do. They calculate across rows without removing any of them. In the previous article, you learned about aggregation and subqueries. Window functions are the next level. What Are Window Functions? A window function performs a calculation across a set of rows that are related to the current row. This set of rows is called a window. ...

June 15, 2026 · 11 min

SQL Tutorial #4: Aggregation and Subqueries — Summarizing Data

You know how to get individual rows. But what if you need answers like “How many books did we sell?” or “What is the average book price?” That is where aggregation comes in. In the previous article, you learned how to combine tables with JOINs. Now you will learn how to summarize data across many rows into a single answer. Aggregate Functions Aggregate functions take many rows and return a single value. ...

June 15, 2026 · 10 min

SQL Tutorial #3: JOINs — Combining Data from Multiple Tables

So far, you have worked with one table at a time. But real databases have many tables, and the interesting answers come from combining them. In the previous article, you learned how to add and modify data. Now you will learn how to pull data from multiple tables at once using JOINs. Why Tables Are Related In our bookstore database, we have separate tables for books and authors. Why not put everything in one table? ...

June 15, 2026 · 12 min

SQL Tutorial #2: INSERT, UPDATE, DELETE — Modifying Data

In the previous article, you learned how to read data with SELECT. But a database is not useful if you cannot add, change, or remove data. This article covers the three commands that modify data: INSERT, UPDATE, and DELETE. You will also learn about transactions — a way to make sure your changes are safe. Our Sample Database We continue with the same online bookstore database. If you need to set it up, copy the CREATE TABLE and INSERT statements from the first article. ...

June 14, 2026 · 10 min

SQL Tutorial #1: SQL Basics — SELECT, WHERE, and Your First Queries

You have data. You need to get answers from it. SQL is the language that does this. Every app you use — social media, banking, shopping — stores data in a database. SQL is how developers read, filter, and organize that data. It has been around since the 1970s, and it is still the most important skill for working with data. What Is SQL? SQL stands for Structured Query Language. It is a language for talking to databases. You write a query, and the database gives you the answer. ...

June 14, 2026 · 10 min

Docker Tutorial #5: Deploying with Docker — From Local to Production

In the previous tutorials, we learned how to build images, run containers, use Compose, and manage volumes and networks. Everything so far happened on your local computer. Now it is time to deploy. In this tutorial, you will learn how to move your application from your laptop to a production server. The Deployment Workflow Deploying with Docker follows a simple pattern: Build the image on your computer (or in CI/CD) Push the image to a registry Pull the image on the server Run the container on the server Your Computer Registry Server ┌──────────┐ ┌──────────────┐ ┌──────────┐ │ Build │────►│ Docker Hub │────►│ Pull │ │ Image │push │ or ghcr.io │pull │ & Run │ └──────────┘ └──────────────┘ └──────────┘ Docker Hub — The Default Registry Docker Hub is the default place to store and share images. It is free for public images and offers one private repository on the free plan. ...

June 14, 2026 · 9 min