Part 4: Environment Mastery - Customizing Your Shell
Table of Contents
Learn to customize your shell with environment variables, aliases, and the .bashrc file Welcome to Part 4! Now we’ll make the terminal truly yours by customizing your shell environment. Your shell is the program that interprets your commands. Most Linux systems use Bash (Bourne Again SHell), but others like Zsh and Fish are popular too. Check your shell: Exercise 4.1: Environment variables are like global settings for your shell. They store information that programs can access. Exercise 4.2: When you type Exercise 4.3: Temporary (current session only): Permanent (edit Exercise 4.4: The Location: Exercise 4.5: ⚠️ Important: Always backup before editing! Apply changes: Aliases are shortcuts for long commands. They make you faster and save typing. Temporary (current session): Permanent (add to Exercise 4.6: Open your Exercise 4.7: The prompt is the text before your cursor. By default: See your current prompt: Prompt escape codes: Exercise 4.8 - Simple custom prompt: Make it permanent - add to Now let’s do something cool! We’ll install and configure berzifetch - a system information tool written by a friend. berzifetch displays your system information in a beautiful format. Think of it like Repository: github.com/Spirizeon/berzifetch Exercise 4.9: Copy to a directory already in PATH: Let’s make it run every time you open a terminal! Exercise 4.11: Now every new terminal shows your system info! Functions are like aliases on steroids - they can accept arguments! Exercise 4.12 - Add these functions to Usage: Ready to practice? Complete the hands-on challenge in the workshop repository: Challenge: Customize your shell with useful aliases and functions to boost your productivity. The challenge includes: Clone the repository and give it a try: Different files load at different times: Best practice: Put everything in Navigation
Understanding Your Shell
# Output: /bin/bash (or /bin/zsh, etc.)
Environment Variables
Viewing Environment Variables
|
Understanding
$PATH$PATH is critical. It’s a colon-separated list of directories where the shell looks for commands.
# Output: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
ls, the shell searches these directories in order:/usr/local/bin/ls/usr/bin/ls ← Found! (stops searching)/bin/ls
Setting Environment Variables
# Add to PATH
.bashrc or .bash_profile):# We'll do this in the next section!
# Try in a new terminal - it's gone! (temporary)
Common Environment Variables
The
.bashrc File.bashrc file is a script that runs every time you open a new terminal. This is where you customize your shell!~/.bashrc (hidden file in your home directory)
|
|
Editing
.bashrc
# OR
# OR
Aliases - Your Personal Shortcuts
Creating Aliases
.bashrc):
# Add at the end:
# alias ll='ls -la'
# alias gs='git status'
# alias ..='cd ..'
# Create temporary aliases
# Try them
Useful Aliases to Add
.bashrc and add these:# Navigation
# Listing
# Safety
# Confirm before delete
# Confirm before overwrite
# Confirm before overwrite
# Git shortcuts
# System
# Quick edit
# Miscellaneous
# Add these to your .bashrc
# Add at the end:
# Save (Ctrl+O, Enter, Ctrl+X in nano)
# Test
Viewing and Removing Aliases
# Show specific alias
Customizing Your Prompt (
$PS1)user@hostname:~$
# Output: \u@\h:\w\$
\u - Username\h - Hostname\w - Full working directory\W - Current directory name only\$ - $ for normal user, # for root\d - Date\t - Time (24-hour)\n - Newline# Try these (temporary)
PS1="\u@\h:\w\$ " # Default
PS1="[\t] \u:\w\$ " # Add time
PS1="\w > " # Minimalist
PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " # Colors!
.bashrc:# Colorful prompt (green user@host, blue directory)
PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
The berzifetch Project
What is berzifetch?
neofetch but customizable!Installing berzifetch
# Clone the repository
# Read the README
# Try it
Adding berzifetch to Your PATH
# Now you can run: berzifetch (from anywhere)
# Reload
# Verify
Creating a berzifetch Alias
# Add at the end:
# OR make it auto-run on terminal startup:
# Save and reload
Functions in
.bashrc.bashrc:# Create a directory and enter it
# Extract any archive
# Quick backup
# Find process by name
Hands-On Challenge
Advanced: Shell Configuration Files
.bashrc, then have .bash_profile source it:# ~/.bash_profile
if [; then
fi
Quick Reference Card
# Environment Variables
# Set variable
# Configuration
# Aliases
# Create alias
# Functions
# PATH Management
# Add to PATH