Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Commands»How to Create Shortcut Commands using Alias in Linux

    How to Create Shortcut Commands using Alias in Linux

    By RahulMarch 30, 20202 Mins ReadUpdated:April 13, 2020

    In this tutorial you will learn, how to create shortcut commands on Linux. This is you can say a short name of any command. In you daily work, you use multiple commands very frequently. You can create a shortcut of those commands, which help you to use easier.

    Advertisement

    Alias is an Linux command provides ability to create customized commands. Using this you can create a sort name for a big command as an alias, which is easier to remember. When we uses a single command very frequently, we can alias them to a very short name. You can understand it as create shortcut commands on Linux.

    Create Shortcut Command

    For example, we use below command frequently to view the directory listing in human readable format.

    ls -lh
    

    Now, make it short with alias command.

    alias lh="ls -lh"
    

    All done, You have created the alias successfully. To verify the newly created alias, just type below command on terminal

    lh
    

    Create shortcut command linux

    You will see the results on screen similar to command “ls -lh”.

    Make Shortcut Permanent

    When you create an alias on terminal, it is not available permanently. Once the terminal is closed, the aliase are lost. To make the aliases permanently you can write in login or non login shell script.

    Add the aliases in /etc/profile.d/bash_aliases.sh (Use any name for this script) to make them available for all users. To configure aliases for specific user only, add them in ~/.bash_aliases file.

    Create More Shortcut Commands

    You can create multiple shortcut commands as much you need. Here is the aliases of some frequently used commands. Add these commands to shell script.

    alias cd..='cd ..'
     
    alias ..='cd ..'
    alias ...='cd ../../../'
    
    alias reboot='sudo /sbin/reboot'
    alias poweroff='sudo /sbin/poweroff'
    
    alias apache2restart='sudo sytemctl restart apache2.service'
    alias apache2reload='sudo sytemctl reload apache2.service'
    

    View all Shortcuts (Aliases)

    You can simply type the “alias” command without any parameter to print all available aliases on your system.

    alias
    

    Linux show alias

    Remove Shortcuts

    You can use unalias command to disable any shortcut on your system. For example to disable ‘lh’ alias use following command.

    unalias lh
    

    You also need to remove any entry made in login or non login shell scripts.

    alias command unalias
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Sed Command to Delete Lines in a File

    Sed Command to Delete Lines in a File

    Sort Command in Linux with Practical Examples

    15 Practical Examples of Sed Command

    Sed Command in Linux with 15 Practical Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.