Linux: Phase 1 Mini Project

This is the Phase 1 capstone project. You'll apply everything from the first 5 lessons — file operations, directory navigation, terminal shortcuts — to build a usable, well-organized personal Linux development environment from scratch.

📋 Prerequisites: You should first complete

1. What You Will Learn


2. Alex's "Messy Environment" Story

(1) The Pain: Files Scattered Everywhere, Finding Things Is Like a Treasure Hunt

Alex had been using Linux for three months, but each session was more painful than the last:

(2) The Standardization Solution

Alex decided to spend 10 minutes organizing his development environment using Phase 1 skills: standard directories + practical aliases + runtime installation. After that, his terminal commands went from 10 keystrokes to 2.

(3) The Benefit: Order Brings Efficiency

A standardized development environment means Alex doesn't have to "think" about where files are — fixed directory structures, quick command aliases, and ready-to-use development language environments save him at least 30 minutes every day.


3. Knowledge Points

(1) Standard Project Directory Structure

A good development environment starts with directory structure. Here's a recommended developer layout:

TEXT

~/projects/          # All projects
├── web/             # Web projects
│   ├── frontend/
│   └── backend/
├── scripts/         # Shell scripts
├── learning/        # Learning experiments
├── notes/           # Notes and documentation
└── tmp/             # Temporary files (can be cleaned anytime)

(2) PS1 — Customizing the Shell Prompt

The PS1 (Prompt String 1) environment variable controls what your terminal prompt looks like.

BASH
# Default format
# user@host:current_dir$

# Common customizations
export PS1='\u@\h:\w\$ '           # user@host:/path/to/dir$
export PS1='\[\033[01;32m\]\u\[\033[00m\]:\w\$ '     # With color
export PS1='\n\[\033[1;34m\]\w\[\033[0m\]\n\$ '       # Two-line display

ℹ️ Note: In PS1 escape sequences, \u is the username, \h is the hostname, \w is the full path, and \W shows only the current directory name. A two-line prompt (adding \n in PS1) doesn't compress your input space when paths are long — highly recommended.

Common escape sequences:

Escape Meaning
\u Current username
\h Hostname (short format)
\w Current working directory (full path)
\W Current directory name (last component only)
\d Date
\t Time (24-hour format)
\$ # (root) or $ (regular user)
\n Newline

(3) alias — Give Your Commands a Nickname

BASH
# Basic syntax
alias shortname='long-command'

# Common aliases
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'
alias gs='git status'
alias gc='git commit'
alias gp='git push'
alias cls='clear'

> 💡 Tip: The greatest value of aliases is shortening frequent long commands to two or three letters — like `ll` instead of `ls -la`, or `..` instead of `cd ..`. Start with the 3-5 most commonly used aliases rather than setting up dozens at once.

(4) .bashrc Configuration File

~/.bashrc is the configuration file loaded when bash starts. Every time you open a new terminal window, bash executes all commands in .bashrc.

BASH
# Edit .bashrc
nano ~/.bashrc

# Apply changes immediately (without closing and reopening the terminal)
source ~/.bashrc

(5) ▶ Example: Create Standard Directory Structure

BASH
# Go to home directory
cd ~

# Create and verify standard directories
mkdir -p ~/projects/{web,scripts,learning,notes,tmp}

# View the result
ls -la ~/projects

Output:

TEXT
total 28
drwxr-xr-x  1 alice alice 4096 Jul  8 10:23 .
drwxr-xr-x  1 alice alice 4096 Jul  8 10:23 ..
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 learning
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 notes
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 scripts
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 tmp
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 web

(6) ▶ Example: Customize PS1 Prompt (Temporary)

BASH
# Try different prompts in the current terminal
export PS1='\u:\w\$ '
# Result: alice:/home/alice$

export PS1='\n\[\033[1;32m\]\u@\h\[\033[0m\]\n\w\$ '
# Result: (green) username@hostname
#         /current/path$

Output:

TEXT
alice:/home/alice$

alice@ubuntu
/home/alice$

(7) ▶ Example: Add Aliases (Permanent)

BASH
# Edit .bashrc
echo '# My custom aliases' >> ~/.bashrc
echo "alias ll='ls -la'" >> ~/.bashrc
echo "alias ..='cd ..'" >> ~/.bashrc
echo "alias cls='clear'" >> ~/.bashrc
echo "alias myip='curl -s ifconfig.me'" >> ~/.bashrc

# Apply changes
source ~/.bashrc

# Test
ll
myip

Output:

TEXT
total 48
drwxr-xr-x  1 alice alice 4096 Jul  8 10:23 .
drwxr-xr-x  1 alice alice 4096 Jul  8 10:23 ..
-rw-r--r--  1 alice alice 3771 Jul  8 10:23 .bashrc
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 projects
203.0.113.42

(8) ▶ Example: Install Python and Node.js

BASH
# Install Python3 and pip
sudo apt update
sudo apt install -y python3 python3-pip

# Verify
python3 --version
# Output: Python 3.10.12

# Install Node.js (from NodeSource official repository)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

# Verify
node --version
# Output: v20.12.0
npm --version

Output:

TEXT
Python 3.10.12
v20.12.0
10.5.0

(9) ▶ Example: Verify Environment Is Ready

BASH

echo "=== Operating System ===" && lsb_release -d
echo "=== Home Directory Structure ===" && ls -la ~/projects/
echo "=== Shell ===" && echo $SHELL
echo "=== Python ===" && python3 --version
echo "=== Node.js ===" && node --version
echo "=== Aliases ===" && alias | head -5
echo "=== PS1 ===" && echo $PS1

Output:

TEXT
=== Operating System ===
Description:    Ubuntu 22.04.3 LTS
=== Home Directory Structure ===
total 28
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 learning
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 notes
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 scripts
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 tmp
drwxr-xr-x  2 alice alice 4096 Jul  8 10:23 web
=== Shell ===
/bin/bash
=== Python ===
Python 3.10.12
=== Node.js ===
v20.12.0
=== Aliases ===
alias cls='clear'
alias la='ls -A'
alias ll='ls -la'
=== PS1 ===
\[\033[1;32m\]\u\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]\$ 

(10) ▶ Comprehensive Example: Complete Development Environment Setup Script

Save this script as ~/setup-dev.sh and run it once to complete all configuration:

BASH
#!/bin/bash

set -e  # Exit immediately on error

echo "Setting up Linux development environment..."

# 1. Create directory structure
mkdir -p ~/projects/{web,scripts,learning,notes,tmp}
echo "✅ Directory structure created"

# 2. Configure .bashrc aliases and PS1
cat >> ~/.bashrc << 'EOF'

# ---- Custom configuration starts ----

# Aliases
alias ll='ls -la'
alias la='ls -A'
alias ..='cd ..'
alias cls='clear'
alias myip='curl -s ifconfig.me'

# PS1 prompt
export PS1='\[\033[1;32m\]\u\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]\$ '

# ---- Custom configuration ends ----
EOF
echo "✅ .bashrc configured"

# 3. Install development tools
sudo apt update
sudo apt install -y build-essential curl wget git vim htop
echo "✅ Development tools installed"

# 4. Verify
source ~/.bashrc
echo "=== Environment Verification ==="
echo "Python: $(python3 --version 2>/dev/null || echo 'not installed')"
echo "Node.js: $(node --version 2>/dev/null || echo 'not installed')"
echo "Git: $(git --version 2>/dev/null || echo 'not installed')"

echo "✅ All done! Run source ~/.bashrc or reopen your terminal"
BASH
# Run the script
chmod +x ~/setup-dev.sh
./setup-dev.sh

❓ FAQ

Q: What's the difference between .bashrc and .bash_profile? A: \1

Q: Do aliases survive a reboot? A: Only for the current terminal session (temporary). To make them permanent, you must write the alias commands into ~/.bashrc.

Q: How do I make aliases work for all users? A: Write them into the global configuration /etc/bash.bashrc or /etc/profile.d/custom.sh (requires root privileges).

Q: Can the PS1 prompt show the Git branch? A: Yes. Use the __git_ps1 function (requires bash-completion) or add $(git branch 2>/dev/null | grep '*' | sed 's/* //') to your PS1.

Q: How do I recover if I break my environment? A: If .bashrc is misconfigured, start a bare bash with bash --noprofile --norc and then edit and fix it. Or back up in advance with cp ~/.bashrc ~/.bashrc.backup.


📖 Summary


📝 Exercises

  1. Basic (Difficulty ⭐): Create your personal development directory structure (at least projects/scripts/learning) and configure 3 useful aliases (e.g., ll, .., cls) in .bashrc
  2. Intermediate (Difficulty ⭐⭐): Customize PS1 to show username, current directory, and Git branch, and install a development language runtime (Python or Node.js)
  3. Advanced (Difficulty ⭐⭐⭐): Write a ~/projects/scripts/info.sh script that outputs system version, kernel, disk, and memory info, with set -e error handling and formatted output
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏