Skip to main content

Command Line

1. Common command Line

# Show files and folders
ls # List files in the current directory
ls -a # Show hidden files (starting with .)
ls -l # Show detailed information
ls -la # Show all files + detailed information (most common)

# Show current location
pwd # Print Working Directory

# Change directory
cd folder # Go into a folder
cd .. # Go up one directory
cd ~ # Go to home directory # tilde
cd / # Go to root directory

# Create files and folders
mkdir project
mkdir -p a/b/c
touch hello.txt

# Remove files and folders
rm file.txt
rmdir folder
rm -r folder
rm -rf folder

# Copy & Move
cp file1 file2
mv file folder/

# Display file content
cat file.txt

# Find help
man ls

# Environment variables
echo $USER
echo $HOME
echo $SHELL

# Reload shell configuration
source ~/.zshrc
source ~/.bash_profile

# Find text in a file
grep "search_term" file.txt

2.Common Flags

FlagMeaningExample
-aShow hidden filesls -a
-lLong formatls -l
-laLong format + hidden filesls -la
-rRecursiverm -r folder
-fForcerm -f file
-rfRecursive + Forcerm -rf folder
-pCreate parent directoriesmkdir -p a/b/c

3. The Story of Windows Subsystem for Linux (WSL)

wsl

WSL (Windows Subsystem for Linux) lets Windows run a real Linux environment.

The tutor shared that he visited Microsoft and met the engineer responsible for WSL. The Microsoft team was incredibly proud because they had successfully made Linux run on Windows. He joked that years ago this would have been considered "heresy" inside Microsoft because Windows and Linux used to be competitors.

Windows originally uses PowerShell/CMD, but WSL provides the same Linux command-line environment. Developers can use the same commands on Windows, macOS, and Linux.


4. Why Can macOS and Linux Use the Same Commands?

Both are Unix-like operating systems, so they share the same command-line philosophy and most commands:

The history of Unix

Unix (1969)

│ Goal:
│ Build a portable, multi-user operating system.

├──────────────────────────────┬──────────────────────────────
│ │
│ │
│ Unix Philosophy
BSD Unix (1977) (NOT Unix source code)
│ │
│ Goal: │ Goal:
│ Improve Unix with │ Inspire others to build
│ networking (TCP/IP), │ Unix-like systems.
│ developer tools, and │
│ better usability. │
│ │
│ Based on Unix source code. │ Inspired by Unix ideas only.
│ │
▼ ▼
Darwin (1991)
│ Linux
│ │
│ Goal: │ Goal:
│ Combine BSD + Mach │ Create a free Unix-like
│ into Apple's next OS. │ kernel for personal computers.
│ │
│ BSD heritage. │ Written from scratch.
│ │
▼ ▼
(2001) Ubuntu / Debian
macOS │
│ │ Debian (1993):
│ Goal: │ Build Linux by the community.
│ Bring Unix to millions │
│ of users with Apple's UI. │ Ubuntu (2004):
│ │ Make Linux easy for everyone.
│ │
▼ ▼
Today Today
macOS Linux

5. Understanding ~, ., and Paths

~

~ means your Home directory.

cd ~

.

Files beginning with . are hidden configuration files.

Examples:

.git
.gitignore
.zshrc
.bash_profile
.env

But . can also mean the current directory and .. means the parent directory.

cd . # Stay in the current directory
cd .. # Go to the parent directory

When we would like to run a script in the current directory, we can use ./:

./script1.sh # Run a script1 in the current directory
./.script2.sh # Run a hidden script2 in the current directory

4. Terminal, Shell, Bash, Zsh, and PowerShell

You


Terminal


Shell (Bash / Zsh / PowerShell)


Operating System


Hardware
ComponentRole
TerminalThe application where you type commands
ShellInterprets your commands
BashClassic Unix shell
ZshModern Bash-compatible shell (default on macOS)
PowerShellMicrosoft's shell for Windows