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; command3Example:
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_nameExample:
type testOutput:
test is a shell builtinChoose a different name, such as foo:
type fooOutput:
bash: type: foo: not foundSyntax:
alias name='command'alias foo='cd /usr; ls; cd -'Now, running:
fooWill execute all three commands.
type fooOutput:
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 footype foo
Output:
bash: type: foo: not foundAliases 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.