Bash Shell Ignore Aliases and Functions When Running A Command

How do I ignore bash shell aliases or functions when running a command without removing alias or function from memory or current shell session on a Linux or Unix-like systems?

An alias is nothing but shortcut to commands. The alias command allows the user to launch any command or group of commands (including options and filenames) by entering a single word. Aliases are mainly used to abbreviate a system command or add default arguments to a regularly used command.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Time5m

ADVERTISEMENTS

To view defined aliases the following commands can be used:

Run:
$ alias
My bash aliases:

alias cp='cp -i'
alias l='ls $LS_OPTIONS -lA'
alias ll='ls $LS_OPTIONS -l'
alias ls='ls $LS_OPTIONS'
alias mv='mv -i'
alias rm='rm -i'
alias apt-get='apt-get update && apt-get upgrade'

Bash shell ignore aliases or functions when running a command

Simply use a command called command as follows to ignore aliases or functions. For example, on my system I’ve following aliases set:
alias apt-get='apt-get update && apt-get upgrade'
To ignore apt-get alias, enter:
command apt-get -y install nginx

Ignoring bash aliases and functions

You can also use any one of the following syntax too:
\apt-get -y install apache2
"apt-get" -y install htop

Both \ and " symbols allows you to run real apt-get command (or apt command if alias defined) and ignore apt-get/apt alias at the CLI.
Linux and Unix Bash Shell Ignore Aliases and Functions When Running A Command

More about ‘command’ command

Runs COMMAND with arguments ignoring shell functions. If you have a shell function called ls, and you wish to call the command /bin/ls command, you can type:
command ls
If the -p option is given, a default value is used for PATH that is guaranteed to find all of the standard utilities under UNIX / Linux:
command -p ls
The -V or -v option is given, a string is printed describing COMMAND. The -V option produces a more verbose description:
command -v ls

ls is aliased to `ls $LS_OPTIONS'

type command

The type command will print information about alias, function and real command. For example:
type -a apt-get

apt-get is aliased to `apt-get update && apt-get upgrade'
apt-get is /usr/bin/apt-get

Want to suppress shell function lookup? Pass the -f option to the type command:
type -f foo
You can force a PATH search for each NAME, even if it is an alias, biltin, or function, and returns the name of the disk file that would be executed:
type -P ls
type -P bar

Find out if each NAME is alias, keyword, function, builtin, file or or not found, respectively:
type -t ls
type -t date
type -t quote

See type command help for more information:
help type
help command
man bash

Conclusion

You learned how to ignore bash aliases and function without removing them temporarily at the CLI. See the following resources for further information:

🐧 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 VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
5 comments… add one
  • Planet Malaysia Sep 9, 2008 @ 9:00

    how about unalias?

    • Joe May 4, 2015 @ 15:48

      You didn’t even read the first sentence, did you?

  • Philippe Petrinko Apr 2, 2010 @ 7:54

    Thanks Vivek – “command” is new to me.
    It is astonishing how Bash has become a swiss knife shell …

  • 0xmarcin Jan 14, 2017 @ 12:05

    Great post! You saved my life!!!

  • zoyo Aug 20, 2020 @ 13:25

    Great tips. Thx!

Leave a Reply

Your email address will not be published.

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