• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Commands

Command alias in Linux, Unix

Published: June 15, 2017 | Modified: June 24, 2020



Learn how to create, view, and remove command alias in Linux or Unix. Useful to shorten long commands or imposing switches to commands.

Command alias

Command alias in Linux is another (mostly short) version of frequently used command (or command with arguments). It is meant for lessening keystrokes to type long commands and making it fast, easy, and accurate to work in shell. On the other hand, if you want users to use some commands with preferred switch always, you can create an alias of it. For example, rm command can be aliased to rm -i so that it will be always interactive asking the user to confirm his remove operation.

In this article we will see how to create command alias, how to remove the alias, and how to list alias.

How to create alias

Creating alias is an easy job. You have to specify alias and command to alias like below :

# alias ls='ls -lrt'

Here in this example, we are aliasing command ls to ls -lrt so that whenever we type ls command it will long list, reverse order with a timestamp. Saving out time to write long command with arguments. See how differently ls works before and after alias in the below output.

# ls
apache  httpd-2.4.25  httpd-2.4.25.tar  letsencrypt  lolcat-master  master.zip  shti

# alias ls='ls -lrt'

# ls
total 38504
-rw-r--r--.  1 root root  39198720 Dec 19 12:29 httpd-2.4.25.tar
drwxr-xr-x.  5 root root      4096 Dec 26 07:48 lolcat-master
-rw-r--r--.  1 root root    205876 Mar 22 02:21 master.zip
drwxr-xr-x.  2 root root      4096 Mar 29 08:15 apache
drwxr-xr-x. 12  501 games     4096 Mar 29 08:42 httpd-2.4.25
drwxr-xr-x. 14 root root      4096 Apr  3 15:07 letsencrypt
drwxr-xr-x.  2 root root      4096 May 16 01:29 shti

Make a note that this alias will be available in the current shell only. If you want to make it permanent over reboots, spawns over other users and shells then you need to define it in /etc/profile or respective shell profiles of the individual users. Defining it in profiles is the same syntax, just add the above command in a profile file and it will works once the profile is sourced.

List alias in current shell

To view and list all aliases currently active in your shell, just type command alias without any argument.

# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls -lart'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

In the above output you can see all commands on the left of = and values they are aliased for in the right section. These aliases are defined on /etc/profile or user profiles or shell profiles or defined in the shell with alias command.

How to delete alias

In case you want to remove or delete alias you defined, you need to use unalias command. This command takes your alias command (left portion of = in the above listing) as an argument.

# unalias ls

# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

Observe in above output after un-aliasing ls, its alias to ls -lart vanishes from alias listing. Keep in mind that this un-alias is limited to the current shell only. If you want to permanently un-alias command then you need to remove it from the profile file where you have defined it and re-source that profile.

Fun in terminal using alias

By now you know how alias works, you can play around to have some fun in the terminal. You can alias funny statements to commonly used commands. For example aliasing ls to cmatrix command to run matrix green falling code in terminal and stun user!

# alias ls=' echo I love kerneltalks.com :D'
# ls
I love kerneltalks.com :D

As you know how it can turn evil if it gets into the wrong hands! So be extra cautious when defining an alias for destructive commands. 

⇠ Previous article
Configuration of iptables policies
Next article ⇢
Blog enhancements for better SEO

Related stuff:

  • How to create tar file in Linux or Unix
  • Difference between hard link and soft link
  • bdf command formatted output in hpux
  • cut command and its examples
  • How to save top command output in file
  • xfs file system commands with examples
  • sar command (Part III) : Disk, Network reporting
  • How to change process priority in Linux or Unix
  • 5 different examples to send email through Linux terminal
  • sar command (Part II) : CPU, Memory reporting
  • sar command (Part I): All you need to know with examples
  • How to configure kubectl for AWS EKS

Filed Under: Commands Tagged With: alias command, alias in linux, create alias in linux, how to check alias, how to remove alias, how to unalias, how to view alias, unalias command

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

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

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.