Theme editor

Guide Linux Guide to Creating Command Shortcuts (Aliases) in Linux - 2025

  • Thread starter Thread starter CL4Y
  • Start date Start date
  • Views 241

CL4Y

Keyboard Ninja
Administrator
Thread owner

Guide to Creating Command Shortcuts (Aliases) in Linux – 2025 ⌨️

The Linux terminal is a powerful and flexible tool. However, frequently typing long commands can become tiring over time and slow down your workflow. That’s exactly where command shortcuts (aliases) come to the rescue. An alias allows you to assign a shorter word of your choice to a long or complex command. This way, you can run the entire command by typing just a few characters.

What Is an Alias and Why Use It?

An alias is an alternative name you assign to a command, program, or command sequence. Using aliases can save a significant amount of time, especially for repetitive tasks. For example, instead of typing the full command openvpn3 session-start --config /home/ahmet/VPN/VPN-Ahmet.ovpn, you could assign the alias vpnstart and simply type that whenever you want to run your VPN file.



Step 1: Creating a Temporary Alias

The simplest way to define an alias is by typing it directly into the terminal. This method is only valid for the current terminal session—once you close the terminal, the alias is lost.

Bash:
alias shortcut_name='command'

Example: Let’s say you want to assign a shortcut to the command mkdir ahmet. Enter the following command in the terminal:

Bash:
alias ahmet='mkdir ahmet'

Now, simply typing ahmet in the terminal will execute the mkdir ahmet command.



Step 2: Creating a Permanent Alias​

Instead of redefining aliases every time, it’s better to make them permanent. This is done by adding your alias definitions to a user profile file (typically .bashrc or .zshrc).

Depending on the shell you use, you'll need to edit a hidden file in your home directory:
  • For Bash users: ~/.bashrc
  • For Zsh users: ~/.zshrc
  • You can open these files with a text editor like nano or vim. For example: nano ~/.bashrc

At the bottom of the file, add the alias command you want to define. It's recommended to place each alias on a separate line.

Bash:
alias ahmet='mkdir ahmet' // Creates a folder named ahmet; use by typing ahmet
alias update='sudo apt update && sudo apt upgrade -y' // Updates and upgrades your system; use by typing update

If you're using nano, press Ctrl + X. When prompted to save the file, press Y and then Enter.

To apply the changes immediately, restart the terminal or reload the profile file with one of the following commands:
source ~/.bashrc or source ~/.zshrc

jetto-linux-alias-creat.webp
 
Back
Top