[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedSeptember 13, 2023

How to use alias command in Linux.

How To Use Alias Command.

Depending on the type of work you do on your Linux system, you may need to enter the same long and complicated commands frequently. The alias command lets you create shortcuts for these commands, making them easier to remember and use.

In Linux, an alias is a shortcut that references a command. An alias replaces a string that invokes a command in the Linux shell with another user-defined string.

Aliases are mostly used to replace long commands, improving efficiency and avoiding potential spelling errors. Aliases can also replace commands with additional options, making them easier to use.

 

Linux Alias Syntax

The alias command uses the following syntax:

alias [option] [name]='[value]'

The different elements of the alias command syntax are:

  • alias: Invokes the alias command.

  • [option]: Allows the command to list all current aliases.

  • [name]: Defines the new shortcut that references a command. A name is a user-defined string, excluding special characters and ‘alias’ and ‘unalias’, which cannot be used as names.

  • [value]: Specifies the command the alias references. Commands can also include options, arguments, and variables. A value can also be a path to a script you want to execute.

 

Create Aliases in Linux

There are two types of aliases to create in Linux:

  • Temporary. Add them using the alias command.

  • Permanent. These require to edit system files.

 

Create a Temporary Alias in Linux

Use the alias command to create a temporary alias that lasts until the end of the current terminal session. For instance, creating c as an alias for the clear command:

alias c='clear'

If you want to reference any additional command options when creating an alias, include them as a part of the value. For example, adding move as an alias for the mv command with the option of asking for confirmation before overwriting:

alias move='mv -i'

Another use for aliases is to create a shortcut for running scripts. To do this, provide the absolute path to the script as the value:

alias frename='Example/Test/file_rename.sh'

In this example, using frename as a command runs the file_rename.sh bash script.

 

Create a Permanent Alias in Linux

To make an alias permanent, you need to add it to your shell configuration file. Depending on the type of shell you are using, use:

  • Bash shell: ~/.bashrc

  • Zsh shell: ~/.zshrc

  • Fish shell: ~/.config/fish/config.fish

Start by opening the shell configuration file in a text editor. In this example, we are using the Bash shell and nano text editor:

sudo nano ~/.bashrc

Scroll down until you find a section that lists default system aliases. For ease of use, create a separate section with a descriptive comment and add your aliases using the alias command syntax.

In our example:

#Custom aliases
alias c='clear'
alias move='mv -i'
alias frename='Example/Test/file_rename.sh'

Once you add all of the new alises, press Ctrl+X, type Y and press Enter to save the changes to the configuration file.

The new aliases automatically load in the next terminal session. If you want to use them in the current session, load the configuration file using the source command:

source ~/.bashrc

 

List All Aliases in Linux

Using the alias command on its own displays a list of all currently set aliases:

alias

Another method is to add the -p flag. This option displays the list in a format suitable for input to the shell:

alias -p

 

Remove Aliases in Linux

To remove an alias, use the unalias command with the following syntax:

unalias [name]

For instance, to remove the frename alias:

unalias frename

Adding the -a option allows you to remove all aliases:

unalias -a

The example above shows how alias does not return any results after the unalias -a command.

 

Conclusion

After reading this tutorial, you should be able to use the alias command to create and manage aliases on your Linux system. This will help streamline your work and make terminal commands easier to use.

Keep reading
How to understand OpenVZ virtualization.
August 28, 2023

How to understand OpenVZ virtualization.

How To Understand OpenVZ Virtualization. OpenVZ is a type of operating system-level virtualization technology that allows for the creation and management of multiple isolated virtual environments, often referred to as containers, on a single physical host. Each container operates as a separate…

Read article
How to understand VMware virtualization?
August 28, 2023

How to understand VMware virtualization?

How To Understand VMware Virtualization? VMware is a virtualization and cloud computing software vendor based in Palo Alto, California. Founded in 1998, VMware is now a subsidiary of Dell Technologies. VMware bases its virtualization technologies on its bare-metal hypervisor ESX/ESXi in x86…

Read article
How to understand hyper-v virtualization.
August 28, 2023

How to understand hyper-v virtualization.

How To Understand Hyper-V Virtualization. Hyper-V, short for Hyper-V Virtualization, is a virtualization technology developed by Microsoft. It allows you to create and manage virtual machines (VMs) on a single physical machine. Virtualization is the process of creating multiple virtual instances…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00