Beginner’s Guide: Getting Started (Step-by-Step)
This tutorial is a practical, step-by-step “getting started” guide for people who are new to working in a command line environment and want to build a solid foundation. You’ll learn what the terminal is, how to navigate your computer using commands, how to create and edit files safely, how to install tools, and how to start a simple project with version control (Git). All examples include real commands you can run.
Table of Contents
- What You’ll Learn
- Prerequisites and Setup
- Step 1 — Open a Terminal
- Step 2 — Understand Where You Are (pwd, ls)
- Step 3 — Move Around (cd)
- Step 4 — Create Folders and Files (mkdir, touch)
- Step 5 — View and Read Files (cat, less, head, tail)
- Step 6 — Copy, Move, Rename, Delete (cp, mv, rm)
- Step 7 — Search and Filter Output (grep, find, pipes)
- Step 8 — Understand Permissions (chmod, chown basics)
- Step 9 — Install Tools (macOS, Linux, Windows)
- Step 10 — Start a Project Folder
- Step 11 — Git Basics (init, add, commit, status, log)
- Step 12 — Create and Run a Tiny Program
- Step 13 — Troubleshooting and Safety Tips
- Next Steps
What You’ll Learn
By the end, you should be able to:
- Use a terminal to navigate directories and inspect files.
- Create, edit, copy, move, and delete files confidently.
- Search for text and files using standard command-line tools.
- Understand basic file permissions and why they matter.
- Install common developer tools.
- Initialize a Git repository and make commits.
- Create a small project and run a simple script.
This guide focuses on commands that work on macOS and Linux (Bash/Zsh) and also provides Windows options (PowerShell and/or WSL). If you’re on Windows and want the most Linux-like experience, consider using WSL (Windows Subsystem for Linux).
Prerequisites and Setup
You’ll need:
- A computer with macOS, Linux, or Windows.
- A terminal application:
- macOS: Terminal (built-in) or iTerm2
- Linux: GNOME Terminal, Konsole, etc.
- Windows: Windows Terminal + PowerShell, or WSL
- Basic comfort typing commands.
A note about “shells”
A shell is the program that reads your commands and runs them. Common shells include:
- bash (common on Linux)
- zsh (default on modern macOS)
- PowerShell (common on Windows)
Most commands below target Bash/Zsh. When Windows differs, you’ll see alternatives.
Step 1 — Open a Terminal
macOS
- Press
Cmd + Space, typeTerminal, press Enter.
Linux
- Search for “Terminal” in your app launcher.
Windows
Option A (recommended for Linux-like commands): WSL
- Install WSL (run in PowerShell as Administrator):
wsl --install - Reboot if prompted.
- Open “Ubuntu” (or your installed distro) from the Start menu.
Option B: Use PowerShell (commands differ from Linux/macOS for some tasks).
Step 2 — Understand Where You Are (pwd, ls)
When you open a terminal, you’re “in” a directory (folder). You need two core commands:
pwd= print working directoryls= list files
Run:
pwd
Example output:
/Users/alex
Now list files:
ls
You might see:
Desktop Documents Downloads Pictures
Useful ls options
ls -lshows a detailed list (permissions, size, date).ls -ashows hidden files (names starting with.).ls -lacombines both.
Try:
ls -la
You’ll likely see entries like .zshrc or .bash_profile. Files beginning with . are hidden by default because they’re usually configuration files.
Concept: Paths (absolute vs relative)
- Absolute path starts at the root
/, e.g./Users/alex/Documents - Relative path starts from your current directory, e.g.
Documents
Understanding paths is essential for not getting lost.
Step 3 — Move Around (cd)
cd means change directory.
Go into Documents:
cd Documents
Confirm:
pwd
Go back up one level:
cd ..
.. means “parent directory”.
Go to your home directory from anywhere:
cd ~
~ is a shortcut for your home folder (like /Users/alex).
Go to the previous directory:
cd -
This toggles between your current and last directory—very handy.
Tip: Use Tab completion
Start typing a folder name and press Tab:
cd Doc<Tab>
The shell will auto-complete if there’s a unique match. This reduces typing and prevents mistakes.
Step 4 — Create Folders and Files (mkdir, touch)
Create a new folder for practice:
cd ~
mkdir cli-practice
cd cli-practice
Create nested folders:
mkdir -p projects/demo
-pcreates parent directories as needed and avoids errors if they already exist.
Create an empty file:
touch notes.txt
List to confirm:
ls -l
Write text into a file (redirects)
You can write text using output redirection:
echo "Hello, terminal!" > notes.txt
>overwrites the file.>>appends to the file.
Append a second line:
echo "This is my second line." >> notes.txt
Step 5 — View and Read Files (cat, less, head, tail)
cat (quick display)
cat notes.txt
Good for small files.
less (scrollable viewer)
less notes.txt
In less:
- Use arrow keys or
Page Up/Downto scroll. - Press
qto quit. - Type
/secondthen Enter to search for “second”.
head and tail
Show the first 10 lines:
head notes.txt
Show the last 10 lines:
tail notes.txt
Follow a file as it grows (common for logs):
tail -f notes.txt
Press Ctrl + C to stop following.
Step 6 — Copy, Move, Rename, Delete (cp, mv, rm)
These commands are powerful. Be careful—especially with deletion.
Copy a file: cp
cp notes.txt notes-copy.txt
Copy a folder recursively:
cp -r projects projects-backup
-rmeans recursive (copy directory contents).
Move or rename: mv
Rename a file:
mv notes-copy.txt notes-renamed.txt
Move a file into a folder:
mkdir archive
mv notes-renamed.txt archive/
Delete: rm
Delete a file:
rm archive/notes-renamed.txt
Delete an empty folder:
rmdir archive
Delete a folder and everything inside:
rm -r projects-backup
Important safety note: rm does not move items to the trash by default. It removes them immediately.
Safer deletion habit
Before deleting many files, list what you’re about to delete:
ls projects-backup
Or use interactive mode:
rm -ri projects-backup
-iprompts you before each removal.-rrequired for directories.
Step 7 — Search and Filter Output (grep, find, pipes)
Searching is where the command line becomes extremely efficient.
Search inside files with grep
Add more content:
echo "error: something went wrong" >> notes.txt
echo "info: all good" >> notes.txt
Search for “error”:
grep "error" notes.txt
Case-insensitive search:
grep -i "ERROR" notes.txt
Show line numbers:
grep -n "info" notes.txt
Pipes: connect commands with |
A pipe takes the output of the left command and feeds it into the right command.
List files and filter for .txt:
ls -la | grep "\.txt"
Find files by name with find
From your cli-practice directory:
find . -name "notes.txt"
Find all .txt files:
find . -name "*.txt"
Find files modified in the last day (Linux/macOS):
find . -mtime -1
Combine find + grep (search text across many files)
Search for “error” in all .txt files:
find . -name "*.txt" -print0 | xargs -0 grep -n "error"
Explanation:
find ... -print0outputs file names separated by a null character (safe for spaces).xargs -0reads those safely.grep -nsearches and shows line numbers.
Step 8 — Understand Permissions (chmod, chown basics)
On Unix-like systems (macOS/Linux), every file has permissions:
- r = read
- w = write
- x = execute
Run:
ls -l
You might see something like:
-rw-r--r-- 1 alex staff 85 Mar 21 10:00 notes.txt
The first part -rw-r--r-- means:
-= regular file (a directory would showd)rw-= owner can read/writer--= group can readr--= others can read
Make a script executable: chmod
Create a simple script:
cat > hello.sh <<'EOF'
#!/usr/bin/env bash
echo "Hello from a script!"
EOF
Try running it:
./hello.sh
You may get “Permission denied” because it’s not executable yet. Fix:
chmod +x hello.sh
Now run again:
./hello.sh
Numeric chmod (common in tutorials)
chmod 644 file= owner read/write, others readchmod 755 file= owner read/write/execute, others read/execute
Example:
chmod 755 hello.sh
Ownership (basic idea)
chown changes owner (often requires admin privileges). Example (Linux):
sudo chown youruser:youruser somefile
If you don’t understand why you need chown, don’t use it yet—incorrect ownership changes can create confusing permission problems.
Step 9 — Install Tools (macOS, Linux, Windows)
Installing tools is a key part of getting started. Below are common approaches.
macOS: Homebrew
Install Homebrew (package manager):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install packages, e.g. Git:
brew install git
Verify:
git --version
Linux: apt (Debian/Ubuntu)
Update package lists:
sudo apt update
Install Git and curl:
sudo apt install -y git curl
Verify:
git --version
curl --version
Linux: dnf (Fedora)
sudo dnf install -y git curl
Windows: winget (PowerShell)
Install Git:
winget install --id Git.Git -e
Verify:
git --version
Windows: WSL package install
Inside WSL (Ubuntu):
sudo apt update
sudo apt install -y git
git --version
Step 10 — Start a Project Folder
A good project structure prevents confusion later. Create a new project directory:
cd ~
mkdir -p projects/first-project
cd projects/first-project
Create a few standard files:
touch README.md .gitignore
mkdir src
Write a README:
cat > README.md <<'EOF'
# First Project
This is my first command-line project.
## Goals
- Practice terminal commands
- Learn Git basics
- Run a small script
EOF
Add a .gitignore to avoid committing junk files:
cat > .gitignore <<'EOF'
# OS files
.DS_Store
# Editor folders
.vscode/
.idea/
# Logs
*.log
EOF
Step 11 — Git Basics (init, add, commit, status, log)
Git tracks changes to files over time. Think of it as a “history system” for your project.
Configure Git identity (do once)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check settings:
git config --global --list
Initialize a repository
Inside your project folder:
git init
Check status:
git status
You’ll see untracked files like README.md.
Stage files (prepare a commit)
git add README.md .gitignore
Check status again:
git status
Commit changes
git commit -m "Initial commit with README and gitignore"
View history:
git log --oneline
Common Git mental model
- Working directory: your files as you edit them
- Staging area (index): what you intend to commit next
- Repository: committed history
This extra “staging” step is why Git can be precise about what goes into each commit.
Step 12 — Create and Run a Tiny Program
You can do this with several languages. Below are two common options: Bash and Python. Choose one (or try both).
Option A: Bash script
Create a script in src:
cat > src/run.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
name="${1:-world}"
echo "Hello, ${name}!"
EOF
Make it executable:
chmod +x src/run.sh
Run it:
./src/run.sh
Run with an argument:
./src/run.sh Alice
Explanation:
set -euo pipefailmakes scripts safer:-e: exit on error-u: error on unset variables-o pipefail: fail if any command in a pipeline fails
"${1:-world}"means “first argument, orworldif not provided”.
Commit it:
git add src/run.sh
git commit -m "Add a simple runnable script"
Option B: Python script
Check Python:
python3 --version
Create a Python file:
cat > src/app.py <<'EOF'
import sys
def main():
name = sys.argv[1] if len(sys.argv) > 1 else "world"
print(f"Hello, {name}!")
if __name__ == "__main__":
main()
EOF
Run it:
python3 src/app.py
python3 src/app.py Alice
Commit it:
git add src/app.py
git commit -m "Add a tiny Python app"
Step 13 — Troubleshooting and Safety Tips
1) “Command not found”
If you run something like:
git --version
…and get command not found, it means:
- The tool isn’t installed, or
- Your
PATHdoesn’t include it.
Fix by installing via your package manager (Homebrew/apt/winget) and reopening the terminal.
2) Spaces in file names
If you create a file like My Notes.txt, commands may treat it as two arguments. Use quotes:
touch "My Notes.txt"
ls -l "My Notes.txt"
Or escape spaces:
ls -l My\ Notes.txt
3) Permission denied
If you see:
Permission deniedwhen running./script.sh: make it executable withchmod +x.- Permission issues when installing system packages: use
sudo(Linux) or install correctly on macOS/Windows.
4) Be careful with sudo
sudo runs commands as an administrator. This is sometimes necessary (installing packages, changing system files), but it also makes it easier to damage your system if you run the wrong command.
A good habit: if you don’t understand what a command does, don’t run it with sudo.
5) Learn to read help pages
Most commands have built-in help:
ls --help
Or manual pages:
man ls
In man:
- Use arrows to scroll
- Press
qto quit - Search with
/pattern
6) Use echo to test expansions
If you’re unsure what a wildcard will match, test it:
echo *.txt
This prints what *.txt expands to before you run something destructive like rm.
7) Understand wildcards
*matches many characters?matches one character
Example:
ls *.md
Lists all Markdown files in the current directory.
Next Steps
Once you’re comfortable with the basics above, here are practical directions to continue:
- Learn a text editor
- Terminal-based:
nano,vim - GUI: VS Code
- Terminal-based:
- Practice Git workflows
- Branching:
git branch,git switch -c feature-x - Merging:
git merge
- Branching:
- Learn environment basics
PATH, shell profiles (~/.bashrc,~/.zshrc)
- Try a real project
- Create a small CLI tool
- Write a script that organizes files
- Build a simple web server (Python
http.server, Node.js, etc.)
A simple branching exercise (optional)
Inside your project:
git switch -c add-usage
Edit README.md to add usage instructions (use cat >> to append):
cat >> README.md <<'EOF'
## Usage
### Bash
./src/run.sh Alice
### Python
python3 src/app.py Alice
EOF
Commit:
git add README.md
git commit -m "Document usage examples"
Merge back to main (your default branch might be master or main):
git switch main
git merge add-usage
View log:
git log --oneline --graph --decorate
Summary Checklist
You can now:
- Navigate:
pwd,ls,cd - Create:
mkdir,touch, redirects (>,>>) - Read:
cat,less,head,tail - Manage:
cp,mv,rm(carefully) - Search:
grep,find, pipes| - Permissions:
chmod +x - Install tools with a package manager
- Use Git:
init,add,commit,status,log - Run a small script/program
If you tell me your operating system (macOS/Linux/Windows) and what you want to build (scripts, web apps, data analysis, etc.), I can suggest a focused “next tutorial” with the exact tools and commands to install.