35

I have an alias for the ls command in my ~/.bashrc file aliased with this one:

alias ls='ls --color=auto'

When I run the ls command in a terminal, the aliased ls (ls --color=auto) runs.

My question is: how can I run the original ls only (not the aliased one), without any extra arguments and without deleting the aliased entry?

5 Answers 5

83

You can bypass aliases by the following methods:

  1. the full pathname of the command: /bin/ls

  2. command substitution: $(which ls)

  3. the command builtin: command ls

  4. double quotation marks: "ls"

  5. single quotation marks: 'ls'

  6. a backslash character: \ls

1
  • 17
    additional precisions in bash : command something bypasses both alias AND function named something. \\something, 'something' and "something" only bypasses alias named something (if a function exist, it will then be called). (alias precede function if both exist and none are bypassed) Sep 17, 2014 at 17:55
13

You can disable an alias using \ in front of command.

So to run the original ls command you need to run it using \ls

For example

  • First creating alias of ls command.

    [guru@guru-Aspire-5738 /]$ alias ls='ls -l'
    [guru@guru-Aspire-5738 /]$ ls
    total 96
    drwxr-xr-x   2 root root  4096 Sep  3 18:31 bin
    drwxr-xr-x   5 root root  4096 Sep 17 02:51 boot
    drwxr-xr-x   2 root root  4096 Sep  3 22:17 cdrom
    drwxr-xr-x  17 root root  4520 Sep 17 21:11 dev
    drwxr-xr-x 153 root root 12288 Sep 17 21:11 etc
    drwxr-xr-x   3 root root  4096 Sep  3 22:17 home
    lrwxrwxrwx   1 root root    37 Sep  8 21:31 initrd.img -> /boot/initrd.img-3.2.0-68-generic-pae
    lrwxrwxrwx   1 root root    36 Sep  3 22:18 initrd.img.old -> boot/initrd.img-3.2.0-
    

    (and many more...)

  • Output of original ls using \ which override the alias.

    [guru@guru-Aspire-5738 /]$ \ls
    bin    etc         lib     opt   sbin     tmp      vmlinuz.old
    boot   home        lost+found  proc  selinux  usr
    cdrom  initrd.img      media       root  srv      var
    dev    initrd.img.old  mnt     run   sys      vmlinuz
    [guru@guru-Aspire-5738 /]$ 
    
0
11

Suspend alias expansion

You could also disable alias expansion for all aliases temporarily, without deleting them:

$ shopt -u expand_aliases
$ command -v ls
/bin/ls

To enable them:

shopt -s expand_aliases
$ command -v ls
alias ls='ls --color=auto'

Note that alias expansion is disabled by default in scripts, but set by default in interactive shells.

7

You could add command before the aliased command, e.g.

command ls

Or run the original executable by combining which

which ls

It will return /bin/ls, therefore with

`which ls`

or

$(which ls)

you could execute that file directly.

6

You can also run the command from its original location /bin/ls instead of ls

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .