Bash Alias Tutorial

28/12/2020

How to use bash aliases

Most of the users like to use shortcuts for running commands. There are many commands in Ubuntu that we need to use regularly. It will be very helpful for us if we are able to run those common commands by typing shortcut commands. Using bash aliases, Ubuntu users can easily create shortcut commands of the large commands those are used frequently. Bash aliases not only makes task easier but also save the time of the users. The user can declare alias temporary or permanently. The temporary aliases can be used as long as the session of the user exists. If the user wants to use shortcut commands every time the session starts then he or she has to create permanent alias by using ~/.bashrc and ~/.bash_profile files. How you can create and use bash aliases in Ubuntu is shown in this tutorial by using some examples.

Example-1: Temporary bash alias declaration

Declaring a temporary bash alias is a very simple task. alias command is used to create a shortcut of any command. For example, ls -la command is a very commonly used command to display the list of all files and folder with permission. You can create the shortcut of this command by using alias command. Suppose, the shortcut command will be L. Run the following commands to create the shortcut of ls -la and test the command.

Check the output of ls -ls command

$ ls -ls

Create alias command for ls -la

$ alias L=”ls la”

Test the shortcut of ls -ls

$ L

After creating alias, the output of “L” and “ls -la” commands will be same.

If the user close the session and again start new session then alias command will not work.

Example-2: Permanent bash alias declaration

To solve the above problem you can create permanent alias command. Suppose you want to create a shortcut of “mkdir” command with alias name “C” and use it permanently. Open ~/.bashrc file in any editor, add alias command in that file, save the file and run command to re-execute the file with added alias command.

Open the file in nano editor.

$ nano ~/.bashrc

Add the alias command in the file and save it.

alias C=”mkdir

Re-execute the file to make the command active.

$ source ~/.bashrc

Test the shortcut command of “mkdir”

$ C TestDir

Example-3: Remove bash alias

unalias command is used to remove the previously created alias command. After using this command the alias will not work. So, if you think you don’t want the shortcut command anymore then you can use alias command to remove it permanently.

Run unalias command to remove previously created shortcut command.

$ unalias L

Check the command is working or not.

$ L

Remove or comment the line that is used for creating alias command from ~/.bashrc file and re-execute it for deleting permanent alias.

You can use alias command on various purposes for creating shortcut of the commands. This tutorial will help to understand the basic use of alias command, so that you can easily apply this command for creating shortcut of your regularly used commands. For more information please watch the video!

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How Does PATH Work in Bash

When you’re typing a command in the Linux terminal, you’re generally calling a program to do a certain job, for example,...
29/12/2020

Find Length of String in Bash

The total number of characters of any string data indicates the length of the string. When we work with string data then...
29/12/2020

Copying Files and Copying Directories on Linux

Linux is a place that can do amazing things when performing almost any task. For enjoying the full power of Linux, it’s...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024