Aliases and Custom Prompts
Create custom command shortcuts with aliases and personalize your terminal prompt for better information at a glance.
Aliases and Custom Prompts is a free DevOps Bootcamp lesson on CoddyKit — lesson 3 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 DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Intro to Aliases & Prompts
Ever wish your common commands were shorter? Or wanted your terminal to look a bit more personal? In this lesson, we'll learn two powerful ways to customize your Linux shell experience: aliases and custom prompts. These tools help you work faster and make your terminal truly yours.
What are Aliases?
An alias is a shortcut or an alternative name for a command or a sequence of commands. Instead of typing a long command every time, you can define a short alias for it. It's like creating a nickname for your favorite commands.
- Saves keystrokes and time.
- Reduces typing errors.
- Personalizes your command line.
Creating a Simple Alias
You can create a temporary alias directly in your terminal using the alias command. The syntax is alias <name>='<command>'. Remember to use single quotes around the command if it contains spaces or multiple commands.
For example, alias ll='ls -lh' creates an alias ll that will execute ls -lh, which lists files in a long format with human-readable sizes.
alias ll='ls -lh'Alias in Action
Once defined, you can use your alias just like any other command. Type ll and press Enter. You'll see the output of ls -lh. Keep in mind, aliases created this way only last for your current terminal session. If you close the terminal, the alias is gone.
alias ll='ls -lh'
llViewing Existing Aliases
To see a list of all currently defined aliases in your shell, simply type the alias command without any arguments. This will show both system-defined aliases and any you've created during your session.
aliasRemoving an Alias
If you no longer need an alias, you can remove it using the unalias command followed by the alias name. This cleans up your shell environment.
For example, unalias ll will remove the ll alias. After running this, ll will no longer execute ls -lh.
alias ll='ls -lh'
unalias llMaking Aliases Permanent
To make an alias available every time you open a new terminal, you need to add it to your shell's configuration file. For Bash, this is usually ~/.bashrc. For Zsh, it's ~/.zshrc.
- Open the file with a text editor (e.g.,
nano ~/.bashrc). - Add your
aliaslines (e.g.,alias ll='ls -lh'). - Save and close the file.
- Apply changes:
source ~/.bashrc(or open a new terminal).
What is a Custom Prompt?
The prompt is the text you see before you type a command in your terminal. By default, it often shows your username, hostname, and current directory. You can customize this prompt to display different information or use colors to make it more visually appealing.
The prompt's appearance is controlled by a special environment variable called PS1.
Basic Prompt Customization
You can change your prompt by setting the PS1 variable. For example, export PS1="MyPrompt> " will immediately change your prompt to MyPrompt> .
Special characters (escape sequences) can add dynamic information:
\u: Username\h: Hostname\w: Current working directory (full path)\$: Displays#if root,$otherwise.
export PS1="\u> "
export PS1="\w\$ "Advanced Prompt with Colors
You can use ANSI escape codes to add colors and formatting to your prompt. These codes need to be enclosed in \[ and \] so Bash knows they are non-printing characters and doesn't mess up line wrapping.
The example below shows a prompt with a green username/hostname and a yellow current directory:
export PS1="\[\e[32m\]\u@\h\[\e[0m\]:\[\e[33m\]\w\[\e[0m\]\$ "Quick Check
You've learned how to create shortcuts and customize your terminal's look. Let's see if you remember the key concepts.
Recap: Shortcuts & Style
- We learned how aliases create handy shortcuts for long or frequently used commands, boosting your efficiency.
- You can make these aliases permanent by adding them to your shell's configuration file (e.g.,
~/.bashrc). - We also explored customizing your terminal's prompt using the
PS1environment variable, adding dynamic information and colors to personalize your workspace. - Experiment with these features to make your command line truly your own!
Frequently asked questions
Is the “Aliases and Custom Prompts” lesson free?
Yes — the full text of “Aliases and Custom Prompts” is free to read here on the web, and the DevOps Bootcamp 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 DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Aliases and Custom Prompts”?
Create custom command shortcuts with aliases and personalize your terminal prompt for better information at a glance. You practise DevOps Bootcamp 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 DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Aliases and Custom Prompts” 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 DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp 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
- Job Control (bg, fg, jobs)
- Shell Expansion & Globbing
- Aliases and Custom Prompts
- Shell Functions & Reusable Snippets