32

An alias for ls command in ~/.bashrc file aliased with this one:

alias ls='ls --color=auto'

then, when I run ls command in terminal aliased ls(ls --color=auto) runs. but my question is how can I run original ls only and only ls alone without extra argument and without solving problem with deleting aliased entry? since when I delete this entry I can run it in simple ls.

Radu Rădeanu
  • 166,822
  • 48
  • 327
  • 400
αғsнιη
  • 35,092
  • 41
  • 129
  • 192

5 Answers5

79

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

terdon
  • 98,183
  • 15
  • 197
  • 293
  • 15
    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) – Olivier Dulac Sep 17 '14 at 17:55
10

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 /]$ 
    
muru
  • 193,181
  • 53
  • 473
  • 722
g_p
  • 18,154
  • 6
  • 56
  • 69
10

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.

Volker Siegel
  • 12,820
  • 5
  • 48
  • 65
6

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.

Zanna
  • 69,223
  • 56
  • 216
  • 327
P.-H. Lin
  • 2,804
  • 1
  • 17
  • 20
5

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

Harris
  • 2,588
  • 16
  • 19