How to Create a Shorthand in Linux Terminal

May 7, 2024 / Servers, Hosting & Email

This tutorial will explain how to create a shorthand in a Linux terminal. In Linux, shorthand commands, also known as aliases, are custom shortcuts that let you execute longer or regularly used commands with a shorter, more memorable name. They can help improve productivity and reduce typing.

Here is how you can create and use aliases in the Linux shell:

  1. Creating Aliases:
    You can define aliases directly in your shell’s configuration file (such as ‘~/.bashrc’ for Bash) or a separate configuration file sourced by your shell. Here is the general syntax to create an alias-

    alias alias_name=’command’

    For example-

    alias ll='ls -l'

    This creates an alias ‘ll’ for the ‘ls –l’ command, so whenever you type ‘ll ’, it will execute ‘ls –l’.

  2. Using Aliases:
    After describing an alias, you can use it in your terminal session just like any other command. For example, after defining the ‘ll’ alias as above, you can simply type ‘ll’ and press Enter to list files in long format.
  3. Persisting Aliases:
    Aliases defined in your shell configuration file will persist across terminal sessions. However, they will not be accessible in other shell sessions unless the configuration file is sourced. To make your changes effective without logging out and back in, you can either-

    1. Run ‘source ~/.bashrc’ (or the appropriate configuration file) to reload the configuration.
    2. Or simply open a new terminal session, and the aliases will be available.
  4. Listing Aliases:
    To list all defined aliases, you can use the ‘alias’ command without any arguments-

    alias

    This will display a list of all defined aliases and their equivalent commands.

  5. Removing Aliases:
    To remove an alias, you can use the ‘unalias’ command followed by the alias name-

    unalias alias_name

    For example-

    unalias ll

    This will remove the ‘ll’ alias.

Aliases offer noteworthy flexibility in tailoring your Linux shell environment to your liking and optimising your workflow. However, it is important to choose aliases carefully to stop any potential misperception or clashes with existing commands, as well as to ensure compatibility with future system updates.

Should you encounter any issues, feel free to get in touch with our support team.

Spread the love