How to create Alias command in Linux

By Dillon Smart · · · 0 Comments

GNU Bash Logo

Alias commands in Linux are a great way to speed up your workflow. In this post, I will show you how to create Alias command in Linux using Bash on WSL (Windows Subsystem for Linux).

What is an Alias command?

The alias command in Linux allows you to create custom shortcuts for frequently used commands. For example, if you frequently use the ls command to list files in a directory, you can create an alias called ll that will execute the ls command with the -l flag (for long listing) automatically.

Examples of Alias commands in Linux

Out of the box, Linux comes with pre-created Alias commands. You likely use these commands regularly without knowing it.

From the terminal, type alias and hit ENTER. This will print all the Alias commands on your system.

Default Alias Commands in Linux

As you can see, there are already a number of Alias commands on your system.

Create a temporary Alias command in Linux

To create an alias command for your current session simply type alias name=command at the command prompt, like so:

alias ll='ls -l'

This will create a temporary alias command that will list the current directory’s contents with the -l flag (for long listing).

To use the new temporary alias in Linux, simply type the name of the command in the terminal.

Create a permanent Alias command in Linux using Bash

To create a permanent alias in Linux, first, open a new terminal. Opening a new terminal window will open your user’s home directory.

Next, open the .bashrc file in an editor like Vim or Nano.

At the bottom of the file, add the following:

alias docs='cd Documents'

Finally, save and exit the file.

The new Alias command will change our directory to the user’s Documents directory when executing the alias ‘docs‘.

How to use Alias commands in Linux

Now we have created our Alias command, close the terminal and re-open a new terminal window.

To execute the new Alias command, simply type ‘docs

Create new Alias command in Linux

Conclusion

Alias commands in Linux are a great way to speed up your workflow when executing repetitive tasks. Create an alias in Linux for long commands to reduce the risks of making a mistake.

I use Alias commands daily to move around the filesystem when configuring new sites.

Learn more about Linux and WSL.

LinuxUbuntuWindows Subsystem for Linux

0 Comment

Was this helpful? Leave a comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

The ULTIMATE guide to setup Windows Subsystem for Linux (WSL) with Ubuntu, Apache2, MySQL and PHP

Updated 16th August 2022

Windows is now good for development! Yes! All thanks to Windows Subsystem for Linux (WSL). No more WAMP or Xampp, WSL can do everything you need. In this ultimate guide to setup Windows Subsystem for Linux with Ubuntu, Apache2, MySQL, and PHP we will cover: What is Windows Subsystem for Linux? Setting up Windows Subsystem

What is WSL?

Updated 13th May 2022

In 2022, web developers have a whole host of options to run development environments on a local machine. With the initial release of WSL in 2016 and the release of WLS2 in 2019, a new environment was presented to web developers. In this post, I will help you answer the question “What is WSL?” What

How to Upload and Download files to and from a Linux server over SSH

Updated 16th August 2022

Its common place to need to upload and download files to and from a remote Linux server. To upload and download files from a remote Linux server you can use the scp (secure copy) command. To download a file you can use: To upload a file you can use: scp /path/to/file/your/uploading username@ip-or-server-name:/path/to/location/to/upload/to Note: It is