Skip to content

A beginner-to-advanced cheat sheet of terminal/CLI commands with explanations and real-world examples for daily practice.

Notifications You must be signed in to change notification settings

ShivjotChoudhary/Terminal-commands-cheat-sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 

Repository files navigation

πŸ–₯️ Terminal Commands Cheat Sheet (Beginner β†’ Advanced)

A simple, practical guide to terminal / command-line usage.
Made for daily practice, real work, and quick revision.


πŸ“ Navigation & Location

pwd β€” Print Working Directory

Shows where you are right now.

pwd

Real case:
You’re lost in folders β†’ run pwd to confirm your exact location.


ls β€” List Files & Folders

ls        # list files
ls -l     # detailed list (size, date, permissions)
ls -a     # include hidden files
ls -lh    # readable file sizes

Real case:
Check whether screenshots, README, or output files exist before moving or deleting.


cd β€” Change Directory

cd folder_name
cd ..
cd ~
cd /Users/username/Desktop

Real case:
Navigate to your project folder before running Python scripts or zipping files.


πŸ“‚ File & Folder Creation

mkdir β€” Make Directory

mkdir screenshots
mkdir project logs backups

Real case:
Create folders to organize images, logs, or backup files before uploading to GitHub.


touch β€” Create Empty File

touch README.md
touch app.py

Real case:
Quickly create files for documentation or starting new code.


πŸ—‘οΈ Delete Files & Folders

rm β€” Remove File

rm file.txt

rm -r β€” Remove Folder

rm -r screenshots

⚠️ Permanent delete (no recycle bin)

Real case:
Delete unused files or wrong screenshots before final submission.


πŸ“„ Copy, Move & Rename

cp β€” Copy Files

cp file.txt copy.txt
cp -r screenshots backup/

Real case:
Create backups before editing important files.


mv β€” Move or Rename

mv old.txt new.txt
mv ui-main.png screenshots/

Real case:
Rename output files or move screenshots into proper folders.


πŸ“¦ Zip & Unzip

zip β€” Create Zip File

zip file.zip file.txt
zip -r project.zip project/
zip -r Matrix-Calculator-macOS.zip "Matrix Calculator.app"

Explanation:

  • -r β†’ recursive (folders)
  • First name β†’ zip file
  • Second name β†’ file/folder to zip

Real case:
Compress project or app files before sharing or uploading.


unzip β€” Extract Zip

unzip project.zip
unzip project.zip -d output_folder/

Real case:
Extract downloaded project or assignment files.


πŸ–ΌοΈ Open Files & Folders (macOS)

open .
open image.png
open "Matrix Calculator.app"

Real case:
Instantly preview images, apps, or folders without Finder clicks.


πŸ” Search Files

find . -name "*.png"

Real case:
Locate all screenshots or images inside a large project.


βš™οΈ Permissions

chmod +x script.sh

Real case:
Make shell or Python scripts executable before running them.


🧹 Clear Terminal

clear

Shortcut: Cmd + K

Real case:
Clean cluttered terminal output to focus on fresh commands.


🧠 System Info

whoami
date

Real case:
Confirm logged-in user or timestamp logs/debug output.


🌱 Git Basics (Only Essentials)

git status
git add .
git commit -m "message"

Real case:
Check changes and save project progress.


πŸ”‘ Important Symbols

Symbol Meaning
. Current directory
.. Parent directory
~ Home directory
/ Root directory
* Wildcard

Example:

rm *.png

Deletes all PNG files in the current folder.


🧠 Real-Life Example Workflow

cd python/GUI_app
ls
mkdir screenshots
mv ui*.png screenshots/
cd screenshots
zip -r ui-images.zip .
open .

πŸ‘‰ Clean β†’ organize β†’ zip β†’ preview β†’ upload.


🎯 Golden Rule

The terminal does exactly what you tell it.

If something fails, always check:

pwd
ls

Python Virtual Environment (venv) Cheat Sheet

A quick reference guide for managing isolated Python environments and dependencies.

πŸ›  Basic Commands

1. Check Python Installation

Confirm Python is installed on your system.

macOS / Linux:

python3 --version

Windows:

python --version

2. Create Project Folder

Keeps your project files organized.

mkdir python_project
cd python_project

3. Create Virtual Environment

Creates an isolated Python environment in a folder named venv.

macOS / Linux:

python3 -m venv venv

Windows:

python -m venv venv

4. Activate Virtual Environment

Switches your terminal to use the isolated Python & pip. Look for (venv) in your prompt.

macOS / Linux:

source venv/bin/activate

Windows (CMD / PowerShell):

venv\Scripts\activate

5. Install Package

Installs a package ONLY inside the virtual environment.

pip install numpy

6. Check Installed Packages

Shows a list of all packages currently installed in the active environment.

pip list

7. Save Dependencies

Saves exact package versions to a file. Critical for sharing projects.

pip freeze > requirements.txt

Example content: numpy==1.26.4

8. Install Dependencies from File

Recreates the exact same environment on another system.

pip install -r requirements.txt

9. Start Python Interpreter

Starts the Python shell.

Inside venv:

python

macOS System (Outside venv):

python3

10. Check Which Python is Running

Confirms if you are using the venv Python or the System Python.

macOS / Linux:

which python

Windows:

where python

11. Deactivate Virtual Environment

Exits the virtual environment and returns to system Python.

deactivate

12. πŸ“‚ File Creation & Editing

Create a New File

Creates an empty file named main.py.

touch main.py

Open File Editor

Opens the file in the simplistic terminal editor (Nano).

nano main.py

Nano Editor Shortcuts

Action Shortcut Description
Save File CTRL + O Press Enter to confirm filename.
Exit Editor CTRL + X Exits Nano (prompts to save if modified).

13. πŸ“„ Viewing & Listing Files

List Files

Shows all files and folders in the current directory.

ls

Read File Content

Prints the entire content of main.py to the terminal screen.

cat main.py

14. πŸš€ Running Python

Run Script

Executes the Python code inside the file.

python main.py

Check Python Path

Shows which Python executable is currently active.

macOS / Linux:

which python

Windows:

where python

15. ✍️ Quick Text Manipulation (Redirection)

Append Text (Safe)

Adds text to the end of the file. Does NOT delete existing content.

echo 'print("Hello World")' >> main.py

Overwrite File (Caution)

Replaces the entire file content with new text. Old content is lost.

echo 'import numpy' > main.py

Write with Newline (Best for Scripts)

Writes formatted text (safely adds a new line \n).

printf 'if __name__ == "__main__":\n    print("Start")\n' >> main.py

About

A beginner-to-advanced cheat sheet of terminal/CLI commands with explanations and real-world examples for daily practice.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published