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
- Lesson 1: Introduction to Linux
- Lesson 2: Installing Linux
- Lesson 3: Terminal Basics
- Lesson 4: Filesystem Navigation
- Lesson 5: File and Directory Operations
1. What You Will Learn
- Project directory structure design
- Shell prompt customization (PS1)
- Aliases and shortcut commands
- Development language runtime installation
- .bashrc configuration file management
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:
- Files he created were scattered across his
~home directory - Every time he checked logs he had to type a long command
- When he needed to check the Java version,
java -versionsaidcommand not found— he didn't know JDK was already installed, just not in his PATH
(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:
~/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.
# 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,
\uis the username,\his the hostname,\wis the full path, and\Wshows only the current directory name. A two-line prompt (adding\nin 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
# 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.
# Edit .bashrc
nano ~/.bashrc
# Apply changes immediately (without closing and reopening the terminal)
source ~/.bashrc
(5) ▶ Example: Create Standard Directory Structure
# 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:
TEXTtotal 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)
# 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:
TEXTalice:/home/alice$ alice@ubuntu /home/alice$
(7) ▶ Example: Add Aliases (Permanent)
# 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:
TEXTtotal 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
# 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:
TEXTPython 3.10.12 v20.12.0 10.5.0
(9) ▶ Example: Verify Environment Is Ready
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:
#!/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"
# Run the script
chmod +x ~/setup-dev.sh
./setup-dev.sh
❓ FAQ
Q: What's the difference between
.bashrcand.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
aliascommands into~/.bashrc.
Q: How do I make aliases work for all users? A: Write them into the global configuration
/etc/bash.bashrcor/etc/profile.d/custom.sh(requires root privileges).
Q: Can the PS1 prompt show the Git branch? A: Yes. Use the
__git_ps1function (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
.bashrcis misconfigured, start a bare bash withbash --noprofile --norcand then edit and fix it. Or back up in advance withcp ~/.bashrc ~/.bashrc.backup.
📖 Summary
- Standard directory structure:
~/projects/{web,scripts,learning,notes,tmp} - PS1 customizes the prompt;
aliasgives commands short names .bashrcis where persistent configuration lives; runsource ~/.bashrcafter changes- Install development runtimes:
sudo apt install python3 nodejs - You can write a
setup-dev.shscript to set up your environment in one click (that's why learning Shell scripting matters)
📝 Exercises
- Basic (Difficulty ⭐): Create your personal development directory structure (at least projects/scripts/learning) and configure 3 useful aliases (e.g.,
ll,..,cls) in.bashrc - Intermediate (Difficulty ⭐⭐): Customize PS1 to show username, current directory, and Git branch, and install a development language runtime (Python or Node.js)
- Advanced (Difficulty ⭐⭐⭐): Write a
~/projects/scripts/info.shscript that outputs system version, kernel, disk, and memory info, withset -eerror handling and formatted output