0Pricing
Linux Command Line Mastery · Lesson

Environment Variables and Aliases

Manage and customize your shell environment using environment variables and command aliases.

Environment Variables and Aliases is a free Linux Command Line Mastery lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Your Shell's Environment

Welcome! In this lesson, we'll dive into how your Linux shell keeps track of important information. This 'environment' helps your commands run smoothly.

Think of it as your shell's personal workspace, full of settings and shortcuts.

Meet Environment Variables

Environment variables are dynamic named values that store information used by the shell and other programs. They let you customize how your system behaves.

  • They are like temporary storage for your shell.
  • They can hold paths, user settings, and more.
  • Other programs can read these variables to know how to act.

Checking Current Variables

You can see all active environment variables using the printenv command. To view a specific variable, use echo $VARIABLE_NAME.

The dollar sign $ before a variable name tells the shell to show its value.

printenv | head -n 3
echo $HOME

Important System Variables

Two very common and important environment variables are PATH and HOME:

  • PATH: A list of directories where the shell looks for executable commands. When you type ls, the shell checks these directories.
  • HOME: The absolute path to your home directory. This is where your personal files and settings are usually stored.

Setting Temporary Variables

You can create your own environment variables for the current shell session. Just assign a value to a name:

VARIABLE_NAME="value"

Note that there are no spaces around the = sign. These variables are temporary and disappear when you close the terminal.

MY_MESSAGE="Hello CoddyKit"
echo $MY_MESSAGE

# This variable only exists in this shell

Making Variables Global with 'export'

Variables set directly are only available in the current shell. To make them available to any sub-processes (like scripts or other commands you run from your current shell), you need to export them.

export GLOBAL_VAR="I am global"
bash -c 'echo $GLOBAL_VAR'

# Without export, 'bash -c' wouldn't see it.

Introducing Command Aliases

Command aliases are custom shortcuts for longer commands or sequences of commands. They save you typing and can even fix common typos.

  • They personalize your command-line experience.
  • You define a short name that expands to a longer command.
  • Great for frequently used, complex commands.

Creating Quick Shortcuts

To create an alias, use the alias command followed by name='command'. Like variables, these are temporary and last only for the current shell session.

A common example is aliasing ls -alF to ll for a detailed file listing.

alias ll='ls -alF'
ll

# Now 'll' runs 'ls -alF'

Listing and Removing Aliases

To see all aliases currently active in your shell, simply type alias without any arguments. If you want to remove an alias, use the unalias command.

alias
alias c='clear'
alias
unalias c
alias

Check Your Understanding

You've learned about environment variables and aliases. Let's test your knowledge!

Consider the following:

MY_VAR="Test"
export MY_VAR

Which statement is true after running these commands?

Lesson Summary

Great job! You've successfully explored environment variables and aliases.

  • Environment variables store key-value pairs for your shell and programs.
  • Use echo $VAR to see a variable's value and printenv to list them all.
  • export makes variables available to sub-processes.
  • Aliases are custom shortcuts for commands, created with alias name='command'.
  • Both are temporary by default, lasting only for the current shell session.

Next, you'll learn how to make these customizations permanent!

Frequently asked questions

Is the “Environment Variables and Aliases” lesson free?

Yes — the full text of “Environment Variables and Aliases” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Environment Variables and Aliases”?

Manage and customize your shell environment using environment variables and command aliases. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Command Line Mastery?

No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Environment Variables and Aliases” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Command Line Mastery lesson?

Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Git Basics from the Command Line
  2. Environment Variables and Aliases
  3. Shell Configuration: `.bashrc`, `.zshrc`, `.profile`
  4. Branching and Merging with Git from the Command Line
← Back to Linux Command Line Mastery