Linux offers flexible customization tools for command-line users. Among them, the alias
command lets you create custom shortcuts for frequently used or multi-step commands. This enhances workflow speed and reduces repetitive typing. This article explains how to define, verify, remove, and persist aliases efficiently.
You can chain commands using semicolons:
command1; command2; command3
Example:
cd /usr; ls; cd -
This changes to /usr
, lists its contents, then returns to the previous directory. Such sequences are ideal candidates for alias shortcuts.
Before assigning an alias, use type
to check if the name already exists:
type command_name
Example:
type test
Output:
test is a shell builtin
Choose a different name, such as foo
:
type foo
Output:
bash: type: foo: not found
Syntax:
alias name='command'
alias foo='cd /usr; ls; cd -'
Now, running:
foo
Will execute all three commands.
type foo
Output:
foo is aliased to `cd /usr; ls; cd -'
To see all defined aliases:
alias
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
Use unalias
to delete:
unalias foo
type foo
Output:
bash: type: foo: not found
Aliases created in the terminal last only for the current session. To make them permanent, add them to:
~/.bashrc
~/.bash_aliases
(if your system supports it)The alias
command provides a simple way to enhance command-line efficiency by creating custom shortcuts. With clear naming, proper management, and persistence setup, aliases become a powerful tool for terminal productivity.