Skip to content

alias Command in Linux

Summary

The alias command in Linux allows you to create shortcuts for frequently used commands. This can significantly speed up your workflow by simplifying complex commands or long sequences of commands into shorter, more memorable aliases.

Introduction

The alias command in Linux is used to define or display aliases. An alias is essentially a shortcut for another command or a sequence of commands. When you type an alias, the shell replaces it with the actual command or sequence of commands before executing it. This is a great way to customize your shell environment and make common tasks easier.

Use case and Examples

Creating a simple alias

alias la='ls -la'
This creates an alias named la that executes the command ls -la (which lists all files and directories, including hidden ones, with detailed information).

Listing all defined aliases

alias
This command displays a list of all currently defined aliases in your shell session.

Creating an alias for navigation

alias back='cd ..'
This creates an alias named back to quickly navigate back to the parent directory.

Unalias a previously created alias

unalias la
This command removes the alias la that was previously defined.

Making aliases permanent

To make aliases permanent, you need to add them to your shell configuration file (e.g., .bashrc, .zshrc). Open the file with a text editor:

nano ~/.bashrc
And add your aliases to the end of the file. After saving the file, you need to source it to apply the changes to your current shell session:
source ~/.bashrc

Commonly used flags

Flag Description Example
-p Prints the alias definitions in a reusable format. alias -p
(No Flag) Without any arguments, it lists all current aliases. alias
N/A To unalias a previously defined alias, use the unalias command. unalias myalias


Share on Share on

Comments