Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Commands»How to Create Shortcut Commands using Alias in Linux

    How to Create Shortcut Commands using Alias in Linux

    RahulBy 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.

    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
    Previous ArticleHow to Install Mono on Ubuntu 18.04 & 16.04
    Next Article How to Get IP Address of A Docker Container

    Related Posts

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    (Resolved) -bash: /bin/mv: Argument list too long

    Updated:January 13, 20222 Mins Read

    Tee Command in Linux with Examples

    4 Mins Read

    How to Scan Open Ports with Nmap

    5 Mins Read

    Handling filenames with spaces in Linux

    3 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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