DEV Community

Isabella Otoo
Isabella Otoo

Posted on

Command Line Essentials: Terminal Commands Every Developer Should Know

Command Line Essentials: Terminal Commands Every Developer Should Know

Table of Contents


Introduction

The command line might look intimidating with its black screen and blinking cursor, but it's one of the most powerful tools in a developer's toolkit. In this tutorial, you'll learn the essential terminal commands that will make you more efficient and confident as a developer.

What you'll learn:

  • What the command line is and why it matters
  • Essential commands for navigating your file system
  • How to create, move, and delete files and folders
  • Using Git from the command line
  • Productivity shortcuts and tips
  • How to troubleshoot common issues

Prerequisites:

  • A computer running Windows, macOS, or Linux
  • No prior command line experience required
  • Willingness to experiment (you won't break anything!)

Time to complete: 40-50 minutes


What is the Command Line?

The command line (also called terminal, console, or shell) is a text-based interface for interacting with your computer. Instead of clicking buttons and icons, you type commands to tell your computer what to do.

Real-World Analogy

Think of your computer as a restaurant:

Graphical Interface (GUI):

  • Like a picture menu where you point at what you want
  • Easy to use but limited options
  • Click, drag, drop

Command Line:

  • Like telling the chef exactly what you want
  • More powerful and flexible
  • Type specific instructions

Why It Looks Scary (But Isn't)

When you open a terminal, you see something like:

user@computer:~$
Enter fullscreen mode Exit fullscreen mode

This is just your computer saying "I'm ready for your command!" The blinking cursor is waiting for you to type.


Why Developers Use the Command Line

Speed and Efficiency

With GUI (multiple clicks):

  1. Open File Explorer
  2. Navigate to Documents
  3. Create new folder
  4. Name the folder
  5. Open the folder
  6. Create a new file
  7. Name the file

With command line (one command):

mkdir -p Documents/my-project && cd Documents/my-project && touch index.html
Enter fullscreen mode Exit fullscreen mode

Done in 2 seconds! ⚡

More Control and Power

Some tasks are impossible or difficult with a graphical interface:

  • Batch renaming 100 files
  • Finding all files containing specific text
  • Automating repetitive tasks
  • Managing remote servers
  • Using advanced developer tools

Industry Standard

Professional developers use the command line because:

  • ✅ Many tools only have command line interfaces
  • ✅ Easier to share instructions (copy-paste commands)
  • ✅ Required for server management
  • ✅ Essential for version control (Git)
  • ✅ Faster for complex operations

Opening Your Terminal

Windows

Option 1: Command Prompt

  • Press Windows key + R
  • Type cmd
  • Press Enter

Option 2: PowerShell (Recommended)

  • Press Windows key + X
  • Select "Windows PowerShell"

Option 3: Git Bash (Best for Development)

  • Install Git for Windows
  • Right-click anywhere → "Git Bash Here"

macOS

Option 1: Spotlight

  • Press Cmd + Space
  • Type "Terminal"
  • Press Enter

Option 2: Finder

  • Go to Applications → Utilities → Terminal

Linux

Most distributions:

  • Press Ctrl + Alt + T

Or:

  • Search for "Terminal" in your application menu

Understanding the Command Line Interface

Anatomy of the Command Prompt

When you open your terminal, you'll see something like:

john@macbook:~/Documents$
Enter fullscreen mode Exit fullscreen mode

Let's break this down:

  • john - Your username
  • @ - Separator
  • macbook - Your computer's name
  • : - Separator
  • ~/Documents - Current directory (where you are)
  • $ - Prompt symbol (means you're a regular user)
  • # - Root/admin prompt (if you see this, you have admin privileges)

Understanding Paths

Absolute path - Complete address from the root:

/Users/john/Documents/projects/my-app
Enter fullscreen mode Exit fullscreen mode

Relative path - Address from your current location:

projects/my-app  # If you're already in Documents
Enter fullscreen mode Exit fullscreen mode

Special path symbols:

  • ~ - Your home directory
  • . - Current directory
  • .. - Parent directory (one level up)
  • / - Root directory (Windows uses \)

Essential Navigation Commands

pwd - Print Working Directory

Shows where you currently are in the file system.

pwd
Enter fullscreen mode Exit fullscreen mode

Output:

/Users/john/Documents
Enter fullscreen mode Exit fullscreen mode

Use case: When you're lost and need to know your current location.


ls - List Directory Contents

Shows files and folders in your current location.

Basic usage:

ls
Enter fullscreen mode Exit fullscreen mode

Output:

file1.txt  file2.txt  my-folder  notes.md
Enter fullscreen mode Exit fullscreen mode

Common options:

# List with details (permissions, size, date)
ls -l

# List all files including hidden ones (starting with .)
ls -a

# List in human-readable format with sizes
ls -lh

# Combine options
ls -lah
Enter fullscreen mode Exit fullscreen mode

Example output with -lh:

-rw-r--r--  1 john  staff   2.5K Oct 20 14:30 file1.txt
drwxr-xr-x  3 john  staff    96B Oct 20 14:30 my-folder
Enter fullscreen mode Exit fullscreen mode

Reading the output:

  • - = file, d = directory
  • rw-r--r-- = permissions
  • 2.5K = file size
  • Oct 20 14:30 = last modified date

cd - Change Directory

Moves you to a different folder.

Go to a specific folder:

cd Documents
Enter fullscreen mode Exit fullscreen mode

Go to home directory:

cd ~
# or just
cd
Enter fullscreen mode Exit fullscreen mode

Go up one level:

cd ..
Enter fullscreen mode Exit fullscreen mode

Go up two levels:

cd ../..
Enter fullscreen mode Exit fullscreen mode

Go to previous directory:

cd -
Enter fullscreen mode Exit fullscreen mode

Use absolute path:

cd /Users/john/Documents/projects
Enter fullscreen mode Exit fullscreen mode

Pro tip: Use Tab to autocomplete folder names!

cd Doc[press Tab]
# Autocompletes to: cd Documents/
Enter fullscreen mode Exit fullscreen mode

Working with Files and Directories

mkdir - Make Directory

Creates a new folder.

Create a single folder:

mkdir my-project
Enter fullscreen mode Exit fullscreen mode

Create nested folders:

mkdir -p projects/web-app/src
# Creates: projects, then web-app inside it, then src inside that
Enter fullscreen mode Exit fullscreen mode

Create multiple folders at once:

mkdir folder1 folder2 folder3
Enter fullscreen mode Exit fullscreen mode

touch - Create Empty File

Creates a new file or updates the timestamp of an existing file.

Create a single file:

touch index.html
Enter fullscreen mode Exit fullscreen mode

Create multiple files:

touch index.html style.css script.js
Enter fullscreen mode Exit fullscreen mode

Create file with path:

touch src/components/Header.js
Enter fullscreen mode Exit fullscreen mode

Note: The folder must exist first, or use mkdir -p to create it.


cp - Copy Files and Directories

Copies files or folders from one location to another.

Copy a file:

cp file.txt file-backup.txt
Enter fullscreen mode Exit fullscreen mode

Copy a file to another directory:

cp file.txt ../backup/
Enter fullscreen mode Exit fullscreen mode

Copy a directory and its contents:

cp -r my-folder my-folder-backup
# -r means "recursive" (includes everything inside)
Enter fullscreen mode Exit fullscreen mode

Copy multiple files:

cp file1.txt file2.txt file3.txt destination-folder/
Enter fullscreen mode Exit fullscreen mode

mv - Move or Rename

Moves files/folders or renames them.

Rename a file:

mv oldname.txt newname.txt
Enter fullscreen mode Exit fullscreen mode

Move a file to another directory:

mv file.txt Documents/
Enter fullscreen mode Exit fullscreen mode

Move and rename simultaneously:

mv file.txt Documents/renamed-file.txt
Enter fullscreen mode Exit fullscreen mode

Move a directory:

mv my-folder Documents/projects/
Enter fullscreen mode Exit fullscreen mode

rm - Remove Files and Directories

Deletes files or folders permanently.

⚠️ WARNING: There's no "Recycle Bin" - deleted files are gone forever!

Delete a file:

rm file.txt
Enter fullscreen mode Exit fullscreen mode

Delete multiple files:

rm file1.txt file2.txt file3.txt
Enter fullscreen mode Exit fullscreen mode

Delete a directory and its contents:

rm -r my-folder
# -r means "recursive" (deletes everything inside)
Enter fullscreen mode Exit fullscreen mode

Force delete without confirmation:

rm -rf my-folder
# -f means "force" (no confirmation prompts)
Enter fullscreen mode Exit fullscreen mode

Safe deletion - ask for confirmation:

rm -i file.txt
# Prompts: "remove file.txt? (y/n)"
Enter fullscreen mode Exit fullscreen mode

Pro tip: Use rm -i when starting out to avoid accidents!


find - Search for Files

Finds files and directories based on criteria.

Find by name:

find . -name "*.txt"
# Finds all .txt files in current directory and subdirectories
Enter fullscreen mode Exit fullscreen mode

Find by type:

# Find only directories
find . -type d

# Find only files
find . -type f
Enter fullscreen mode Exit fullscreen mode

Find and delete:

find . -name "*.log" -delete
# Finds and deletes all .log files
Enter fullscreen mode Exit fullscreen mode

Find by modification time:

# Files modified in last 7 days
find . -mtime -7

# Files modified more than 30 days ago
find . -mtime +30
Enter fullscreen mode Exit fullscreen mode

Viewing and Editing Files

cat - Display File Contents

Shows the entire contents of a file.

cat file.txt
Enter fullscreen mode Exit fullscreen mode

Combine multiple files:

cat file1.txt file2.txt
Enter fullscreen mode Exit fullscreen mode

Create a new file with content:

cat > newfile.txt
# Type your content, then press Ctrl+D to save
Enter fullscreen mode Exit fullscreen mode

less - View File Contents (Paginated)

Better for large files - shows content page by page.

less largefile.txt
Enter fullscreen mode Exit fullscreen mode

Navigation in less:

  • Space - Next page
  • b - Previous page
  • q - Quit
  • /search-term - Search forward
  • ?search-term - Search backward
  • G - Go to end
  • g - Go to beginning

head - Show First Lines

Shows the beginning of a file.

# Show first 10 lines (default)
head file.txt

# Show first 5 lines
head -n 5 file.txt
Enter fullscreen mode Exit fullscreen mode

tail - Show Last Lines

Shows the end of a file.

# Show last 10 lines (default)
tail file.txt

# Show last 20 lines
tail -n 20 file.txt

# Follow file updates in real-time (useful for logs)
tail -f logfile.txt
Enter fullscreen mode Exit fullscreen mode

grep - Search Inside Files

Finds text within files.

Search for a word:

grep "error" logfile.txt
Enter fullscreen mode Exit fullscreen mode

Search case-insensitively:

grep -i "error" logfile.txt
# Finds "error", "Error", "ERROR"
Enter fullscreen mode Exit fullscreen mode

Search in multiple files:

grep "TODO" *.js
# Searches all JavaScript files
Enter fullscreen mode Exit fullscreen mode

Search recursively in all subdirectories:

grep -r "function" .
Enter fullscreen mode Exit fullscreen mode

Show line numbers:

grep -n "error" file.txt
Enter fullscreen mode Exit fullscreen mode

Count matches:

grep -c "error" file.txt
Enter fullscreen mode Exit fullscreen mode

nano / vim - Text Editors

Command-line text editors for editing files.

Using nano (easier for beginners):

nano file.txt
Enter fullscreen mode Exit fullscreen mode

Nano shortcuts:

  • Ctrl + O - Save (Write Out)
  • Ctrl + X - Exit
  • Ctrl + K - Cut line
  • Ctrl + U - Paste
  • Ctrl + W - Search

Using vim (more powerful but steeper learning curve):

vim file.txt
Enter fullscreen mode Exit fullscreen mode

Vim basic commands:

  • i - Enter insert mode (start typing)
  • Esc - Exit insert mode
  • :w - Save
  • :q - Quit
  • :wq - Save and quit
  • :q! - Quit without saving

Pro tip: Start with nano until you're comfortable, then learn vim if you want more power.


File Permissions and Ownership

Understanding Permissions

When you run ls -l, you see something like:

-rw-r--r--  1 john  staff  2048 Oct 20 14:30 file.txt
Enter fullscreen mode Exit fullscreen mode

Permission breakdown:

-rw-r--r--
│││││││││
│││└─────── Others can read
│││
││└──────── Group can read
││
│└───────── Group cannot write
│
└────────── Owner can read and write
Enter fullscreen mode Exit fullscreen mode

Permission types:

  • r - Read (4)
  • w - Write (2)
  • x - Execute (1)
  • - - No permission (0)

chmod - Change Permissions

Changes file/folder permissions.

Using symbolic notation:

# Give owner execute permission
chmod u+x script.sh

# Remove write permission from group
chmod g-w file.txt

# Give everyone read permission
chmod a+r file.txt
Enter fullscreen mode Exit fullscreen mode

Using numeric notation:

# 755 = Owner can read/write/execute, others can read/execute
chmod 755 script.sh

# 644 = Owner can read/write, others can only read
chmod 644 file.txt

# 777 = Everyone can do everything (rarely recommended!)
chmod 777 file.txt
Enter fullscreen mode Exit fullscreen mode

Common permission patterns:

  • 755 - Executable files (scripts)
  • 644 - Regular files
  • 600 - Private files (only owner can read/write)

chown - Change Owner

Changes file/folder ownership.

# Change owner
sudo chown newowner file.txt

# Change owner and group
sudo chown newowner:newgroup file.txt

# Change recursively
sudo chown -R newowner folder/
Enter fullscreen mode Exit fullscreen mode

Note: Usually requires sudo (admin privileges).


Using Git from the Command Line

Git is the most popular version control system, and it's primarily used through the command line.

Essential Git Commands

Initialize a new repository:

git init
Enter fullscreen mode Exit fullscreen mode

Check status:

git status
Enter fullscreen mode Exit fullscreen mode

Add files to staging:

# Add specific file
git add file.txt

# Add all files
git add .

# Add all JavaScript files
git add *.js
Enter fullscreen mode Exit fullscreen mode

Commit changes:

git commit -m "Your commit message here"
Enter fullscreen mode Exit fullscreen mode

View commit history:

git log

# Compact view
git log --oneline

# Show last 5 commits
git log -n 5
Enter fullscreen mode Exit fullscreen mode

Create a branch:

git branch feature-name
Enter fullscreen mode Exit fullscreen mode

Switch branches:

git checkout feature-name

# Or create and switch in one command
git checkout -b feature-name
Enter fullscreen mode Exit fullscreen mode

Merge branches:

# Switch to main branch first
git checkout main

# Merge feature branch
git merge feature-name
Enter fullscreen mode Exit fullscreen mode

Clone a repository:

git clone https://github.com/username/repo-name.git
Enter fullscreen mode Exit fullscreen mode

Pull latest changes:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Push your changes:

git push origin main
Enter fullscreen mode Exit fullscreen mode

View remote repositories:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Undo last commit (keep changes):

git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode

Discard local changes:

# Discard changes in specific file
git checkout -- file.txt

# Discard all changes
git reset --hard
Enter fullscreen mode Exit fullscreen mode

Process Management

ps - List Running Processes

Shows currently running processes.

# Show your processes
ps

# Show all processes with details
ps aux

# Find specific process
ps aux | grep node
Enter fullscreen mode Exit fullscreen mode

top - Monitor System Resources

Shows real-time system resource usage.

top
Enter fullscreen mode Exit fullscreen mode

Navigation:

  • q - Quit
  • M - Sort by memory usage
  • P - Sort by CPU usage
  • k - Kill a process (enter PID when prompted)

Alternative (better): Use htop if available

htop
Enter fullscreen mode Exit fullscreen mode

kill - Terminate Processes

Stops a running process.

Kill by process ID:

kill 1234
# Where 1234 is the PID (Process ID)
Enter fullscreen mode Exit fullscreen mode

Force kill:

kill -9 1234
Enter fullscreen mode Exit fullscreen mode

Kill by name:

killall node
# Kills all processes named "node"
Enter fullscreen mode Exit fullscreen mode

Find and kill a process:

# Find the process
ps aux | grep node

# Kill it
kill 1234
Enter fullscreen mode Exit fullscreen mode

Background and Foreground Processes

Run command in background:

node server.js &
# The & runs it in background
Enter fullscreen mode Exit fullscreen mode

See background jobs:

jobs
Enter fullscreen mode Exit fullscreen mode

Bring job to foreground:

fg %1
# Brings job #1 to foreground
Enter fullscreen mode Exit fullscreen mode

Send running process to background:

  • Press Ctrl + Z (pauses process)
  • Type bg (resumes in background)

Command Line Shortcuts and Tips

Keyboard Shortcuts

Navigation:

  • Ctrl + A - Move to beginning of line
  • Ctrl + E - Move to end of line
  • Ctrl + Left/Right Arrow - Move word by word

Editing:

  • Ctrl + U - Delete from cursor to beginning of line
  • Ctrl + K - Delete from cursor to end of line
  • Ctrl + W - Delete word before cursor

History:

  • Up Arrow - Previous command
  • Down Arrow - Next command
  • Ctrl + R - Search command history (type to search, Enter to execute)
  • !! - Repeat last command
  • !$ - Use last argument from previous command

Control:

  • Ctrl + C - Cancel current command
  • Ctrl + D - Exit terminal (or end input)
  • Ctrl + L - Clear screen (same as clear command)
  • Ctrl + Z - Pause current process

Useful Command Combinations

Pipes (|) - Send output of one command to another:

# Count files in directory
ls | wc -l

# Search for error in all logs
cat *.log | grep "error"

# Sort and show unique values
cat file.txt | sort | uniq
Enter fullscreen mode Exit fullscreen mode

Redirection (> and >>) - Save output to file:

# Overwrite file with output
ls > filelist.txt

# Append output to file
echo "New line" >> notes.txt

# Redirect errors
command 2> errors.txt

# Redirect both output and errors
command > output.txt 2>&1
Enter fullscreen mode Exit fullscreen mode

Command chaining:

# Run second command only if first succeeds (&&)
mkdir my-folder && cd my-folder

# Run second command regardless (;)
mkdir my-folder; ls

# Run second command only if first fails (||)
command || echo "Command failed"
Enter fullscreen mode Exit fullscreen mode

Tab Completion

The Tab key is your best friend!

# Type part of command or filename, press Tab
cd Doc[Tab]
# Autocompletes to: cd Documents/

# Double Tab shows all possibilities
git ch[Tab][Tab]
# Shows: checkout, cherry, cherry-pick, etc.
Enter fullscreen mode Exit fullscreen mode

Command History

View command history:

history
Enter fullscreen mode Exit fullscreen mode

Execute command from history:

!123
# Executes command #123 from history
Enter fullscreen mode Exit fullscreen mode

Search history:

# Press Ctrl+R, then type search term
# Press Ctrl+R again to cycle through matches
Enter fullscreen mode Exit fullscreen mode

Clear history:

history -c
Enter fullscreen mode Exit fullscreen mode

Aliases - Custom Shortcuts

Create shortcuts for frequently used commands.

Temporary alias (current session only):

alias ll='ls -lah'
# Now typing 'll' runs 'ls -lah'
Enter fullscreen mode Exit fullscreen mode

Permanent aliases (add to ~/.bashrc or ~/.zshrc):

# Open config file
nano ~/.bashrc  # or ~/.zshrc for Zsh

# Add aliases
alias ll='ls -lah'
alias gs='git status'
alias gc='git commit'
alias gp='git push'

# Save and reload
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Useful aliases:

alias cls='clear'
alias ..='cd ..'
alias ...='cd ../..'
alias projects='cd ~/Documents/projects'
alias gs='git status'
alias gaa='git add .'
alias gcm='git commit -m'
Enter fullscreen mode Exit fullscreen mode

Common Mistakes to Avoid

1. Deleting Without Checking

❌ Dangerous:

rm -rf *
# Deletes EVERYTHING in current directory
Enter fullscreen mode Exit fullscreen mode

✅ Safe approach:

# Always check where you are first
pwd

# List what will be deleted
ls

# Then delete specific things
rm -i file.txt
Enter fullscreen mode Exit fullscreen mode

2. Forgetting Spaces in Commands

❌ Wrong:

cd..
# Error: command not found
Enter fullscreen mode Exit fullscreen mode

✅ Correct:

cd ..
# Space is required
Enter fullscreen mode Exit fullscreen mode

3. Using Absolute Paths When Relative Would Work

❌ Unnecessary:

cd /Users/john/Documents/projects/my-app
Enter fullscreen mode Exit fullscreen mode

✅ Better:

cd ~/Documents/projects/my-app
# or if you're already in Documents:
cd projects/my-app
Enter fullscreen mode Exit fullscreen mode

4. Not Using Tab Completion

❌ Slow:

# Typing out full path manually
cd /Users/john/Documents/projects/very-long-folder-name
Enter fullscreen mode Exit fullscreen mode

✅ Fast:

cd ~/Doc[Tab]/proj[Tab]/very[Tab]
# Let Tab complete the rest!
Enter fullscreen mode Exit fullscreen mode

5. Ignoring Error Messages

Always read error messages! They tell you exactly what went wrong.

Common error:

bash: command not found: node
Enter fullscreen mode Exit fullscreen mode

What it means: The command doesn't exist or isn't installed.

Solution: Install the software or check spelling.


6. Running Commands Without Understanding Them

❌ Dangerous:

# Copying random commands from the internet
sudo rm -rf /
# THIS DELETES YOUR ENTIRE SYSTEM!
Enter fullscreen mode Exit fullscreen mode

✅ Safe:

  • Read what the command does first
  • Use man command to read documentation
  • Test on unimportant files first
  • Ask if you're unsure

Troubleshooting Guide

Issue: "Permission Denied"

Error:

bash: ./script.sh: Permission denied
Enter fullscreen mode Exit fullscreen mode

Solution:

# Make file executable
chmod +x script.sh

# Then run it
./script.sh
Enter fullscreen mode Exit fullscreen mode

Issue: "Command Not Found"

Error:

bash: node: command not found
Enter fullscreen mode Exit fullscreen mode

Possible causes:

  1. Software not installed
  2. Not in your PATH
  3. Typo in command name

Solutions:

# Check if it's installed
which node

# Install if missing (example for Node.js)
# On macOS with Homebrew:
brew install node

# On Ubuntu/Debian:
sudo apt install nodejs

# Check spelling
noed  # Wrong!
node  # Correct!
Enter fullscreen mode Exit fullscreen mode

Issue: "No Such File or Directory"

Error:

bash: cd: Documents: No such file or directory
Enter fullscreen mode Exit fullscreen mode

Solutions:

# Check current location
pwd

# List what's actually there
ls

# Check spelling (case-sensitive!)
cd documents  # Wrong if folder is "Documents"
cd Documents  # Correct
Enter fullscreen mode Exit fullscreen mode

Issue: Terminal Stuck or Frozen

Solutions:

If command is running:

  • Press Ctrl + C to cancel

If terminal is unresponsive:

  • Press Ctrl + D to close
  • Open new terminal window

If process is stuck in background:

# Find the process
ps aux | grep stuck-process

# Kill it
kill -9 PID
Enter fullscreen mode Exit fullscreen mode

Issue: Accidentally Ran Wrong Command

Examples:

Deleted wrong file:

  • If you used rm, file is gone (no undo)
  • Check backups or Time Machine (macOS)
  • Use git checkout file if it's in Git

Changed wrong directory:

cd -
# Goes back to previous directory
Enter fullscreen mode Exit fullscreen mode

Want to undo last change:

# For Git
git checkout -- file.txt

# For general file changes
# No built-in undo - use backups!
Enter fullscreen mode Exit fullscreen mode

Issue: "Cannot Write to File"

Error:

bash: file.txt: Permission denied
Enter fullscreen mode Exit fullscreen mode

Solutions:

# Check current permissions
ls -l file.txt

# Change permissions
chmod u+w file.txt

# Or use sudo (be careful!)
sudo nano file.txt
Enter fullscreen mode Exit fullscreen mode

Practical Examples and Workflows

Example 1: Starting a New Project

# Create project folder and navigate into it
mkdir my-new-project && cd my-new-project

# Create project structure
mkdir src css js img

# Create initial files
touch index.html src/app.js css/style.css

# Initialize Git
git init

# Create README
echo "# My New Project" > README.md

# Check what you created
ls -la
Enter fullscreen mode Exit fullscreen mode

Example 2: Finding and Cleaning Up Old Files

# Find all log files
find . -name "*.log"

# Find log files older than 30 days
find . -name "*.log" -mtime +30

# Delete them (be careful!)
find . -name "*.log" -mtime +30 -delete

# Or move them to archive
mkdir archive
find . -name "*.log" -mtime +30 -exec mv {} archive/ \;
Enter fullscreen mode Exit fullscreen mode

Example 3: Working with Git

# Clone a repository
git clone https://github.com/username/repo.git

# Navigate into it
cd repo

# Create new feature branch
git checkout -b new-feature

# Make changes, then check status
git status

# Add changes
git add .

# Commit
git commit -m "Add new feature"

# Push to remote
git push origin new-feature

# Switch back to main
git checkout main

# Pull latest changes
git pull origin main
Enter fullscreen mode Exit fullscreen mode

Example 4: Batch File Operations

# Rename all .txt files to .md
for file in *.txt; do
  mv "$file" "${file%.txt}.md"
done

# Create 10 numbered files
for i in {1..10}; do
  touch file$i.txt
done

# Find and replace text in all files
find . -name "*.txt" -exec sed -i 's/oldtext/newtext/g' {} \;
Enter fullscreen mode Exit fullscreen mode

Next Steps

Now that you understand command line basics, here's how to continue learning:

Immediate Practice

  1. Complete all examples in this tutorial
  2. Navigate your file system using only the terminal
  3. Try creating a project structure from scratch
  4. Practice Git commands with a test repository
  5. Create useful aliases for your workflow

Intermediate Topics

  • Shell scripting and automation
  • Advanced Git workflows (rebase, cherry-pick)
  • Package managers (Homebrew, apt, npm)
  • Environment variables and PATH
  • SSH and remote server access
  • Cron jobs for scheduling tasks

Advanced Topics

  • Regular expressions with grep and sed
  • AWK for text processing
  • System administration commands
  • Network commands (ping, curl, wget)
  • Process management and system monitoring
  • Custom shell scripts and functions

Key Takeaways

The command line is faster and more powerful than graphical interfaces for many tasks

Essential commands to remember:

  • cd - Navigate directories
  • ls - List contents
  • pwd - Show current location
  • mkdir - Create directories
  • touch - Create files
  • cp - Copy
  • mv - Move/rename
  • rm - Delete (careful!)
  • cat / less - View files
  • grep - Search in files

Use Tab completion to save time and avoid typos

Read error messages - they usually tell you exactly what's wrong

Start with safe commands - use -i flag for confirmations when learning

Practice regularly - command line proficiency comes with repetition

Don't fear mistakes - you can't break anything as long as you avoid sudo rm -rf


Additional Resources


About the Author: Isabella Otoo is a full-stack developer and technical writer passionate about making complex technical concepts accessible to beginners.

GitHub Repository: [https://github.com/Bellagirl-maker]

Last Updated: October 2025

Top comments (0)