34

I like to use bash aliases to customize bash commands. Is there a way to override the bash alias settings, or should I rename the aliases to something different than the original command.

eg: my .bash_aliases includes

alias ls='ls -ltr'

If I want to only retrieve the file name, do I need to rename the alias to something other than 'ls'? Or is there another way?

David LeBauer
  • 31,011
  • 31
  • 115
  • 189
  • 3
    I would have modified names for specialized aliases, so that scripts don't have unintended side effects. Thus ll for your list alias instead of ls. Look at some peoples .bashrc files for hints on how to do things. – Michael Shopsin Nov 03 '10 at 15:38
  • Although @dogbane provided the "correct" answer to the question that I posted, yours is more practical and the one that I will probably use; also thanks for the advice to look at .bashrc files. any in particular that you would recommend? – David LeBauer Nov 03 '10 at 17:40
  • 5
    @Michael: Aliases aren't carried forward (exported) into scripts. – Dennis Williamson Nov 03 '10 at 20:02
  • @Michael, that is very helpful since that is how I will be using it – David LeBauer Nov 03 '10 at 21:10
  • 1
    I looked at the .bashrc files of my local Unix gurus and I read up on shell scripting in the O'Reilly bash Cookbook http://oreilly.com/catalog/9780596526788/ – Michael Shopsin Nov 04 '10 at 13:51
  • @DennisWilliamson Is there a source for this? – Hashim Aziz Jan 30 '21 at 06:10
  • @HashimAziz: `help export` only mentions variables and functions. Note also, but unrelated to the foregoing, that alias expansion is off by default in scripts. – Dennis Williamson Jun 27 '22 at 13:48

2 Answers2

66

Add a \ (backslash) before the command to disable the alias, like this:

\ls

This will invoke the original (un-aliased) ls.

Example:

$ ls #will invoke the alias
total 0
-rw-rw-r--    1 dogbane foo          0 Nov  3 16:04 c
-rw-rw-r--    1 dogbane foo          0 Nov  3 16:04 b
-rw-rw-r--    1 dogbane foo          0 Nov  3 16:04 a

$ \ls #will disable the alias
a  b  c
dogbane
  • 266,786
  • 75
  • 396
  • 414
6

you can use /bin/ls temporarily, or `which ls`

Benoit
  • 76,634
  • 23
  • 210
  • 236