How do I use shell aliases under Linux?

Q. What is a shell alias and how do I use them under Linux?

ADVERTISEMENTS

A. An alias is nothing but a short form of a Linux or UNIX command. You use aliases to save the time. To create an alias use the alias command.

Task: Display current aliases

Type alias command with no arguments or with the -p option prints the list
of aliases in the form alias NAME=VALUE on screen:

$ alias

Output:

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

Task : Create an alias

To create an alias use the alias command as follows:

$ alias c=’clear’

Now, type c and hit enter key to run clear the screen aka run screen command.

Task : Remove or delete an alias

To remove or delete an alias use

$ unalias c

Verify that an alias deleted:

$ alias

See also:

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • Philippe Petrinko Apr 2, 2010 @ 8:22

    Vivek,
    it may be a WORDPRESS bug,
    but check line AFTER “To create an alias use the alias command as follows:”
    It contains wrong characters instead of single quotes, surrounding the word [ clear ]

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.