Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Let's say i have the following alias in bash - alias ls='ls --color=auto' - and i want to call ordinary ls without options. Is the only way to do that is to unalias, do the command and then alias again? Or there is some nifty trick or workaround?

share|improve this question

6 Answers 6

up vote 97 down vote accepted

You can also prefix a back slash to disable the alias: \ls

Edit: Other ways of doing the same include:

Use "command": command ls as per Mikel.

Use the full path: /bin/ls as per uther.

Quote the command: "ls" or 'ls' as per Mikel comment.

You can remove the alias temporarily for that terminal session with unalias command_name.

share|improve this answer
    
This is my standard way to do this. –  ncmathsadist May 25 '12 at 1:34
    
very nice, also works well with tcsh –  Levon May 25 '12 at 13:15
2  
This way is very useful. It only bypasses aliases, not functions, which makes it different from command or builtin. –  Mikel May 25 '12 at 16:31
1  
It seems like l\s does the same thing. Is this behaviour a bug or a feature? –  Niklas B. May 25 '12 at 16:46
    
It's a "feature". Only unquoted aliases are expanded. So you can put it in quotes, or use a backslash anywhere you like. See bash aliases reference. –  Mikel May 25 '12 at 17:55

That's what the command command is for.

Try

command ls

This tells the shell to bypass aliases and functions.

This way is supported by bash, zsh, and ash/dash.

share|improve this answer
1  
Best answer, why is it not the most upvoted, though? :) +1 –  0xC0000022L May 25 '12 at 12:44
4  
Because it adds 8 times the number of characters as the backslash method –  JoelFan May 25 '12 at 13:12
1  
@STATUS_ACCESS_DENIED This also doesn't work with tcsh (and therefore presumably not with csh either). The `\` method does –  Levon May 25 '12 at 13:15
    
@Levon: the question was asked for bash, though ;) ... see the tags. And the reason the other one works is a quirk, nothing else. –  0xC0000022L May 25 '12 at 13:21
    
@STATUS_ACCESS_DENIED ah .. good point re the tag, didn't notice it. Glad the \ works (quirk or not) .. that'll come in useful. –  Levon May 25 '12 at 13:23

The alias is just a defined shortcut. In this example, the alias defined is the string ls, which executes ls --color=auto. If you don't want that behavior, you can call the binary ls using the absolute path.

So executing just /bin/ls will produce output without color because it is not the alias you defined.

You could also change the alias to something different, or add a new alias that executes just ls without the color parameters.

share|improve this answer
    
You have to know where the command is. On some systems, the division between /bin and /usr/bin is arbitrary. –  Keith Thompson May 25 '12 at 20:50

Another way, building upon uther's answer, is to use $(which ...) or `which ...` (using backticks `) to automatically find the executable's path. This will both work in bash:

$(which ls)

`which ls`

Undoubtedly, simply prefixing the command with a \ is much shorter.

UPDATE: According to How to use `which` on an aliased command?, this doesn't seem to be reliable at all.

share|improve this answer
    
What's the brackets for? I guess you mean `which ls` to execute the binary directly. –  amyassin May 25 '12 at 9:34
2  
@amyassin: Both syntaxes are equivalent. (BTW, how did you get the backticks into the code formatting?) –  krlmlr May 25 '12 at 11:25
    
Actually the (which ls) didn't work for me (on Ubuntu 12.04 LTS) And the backticks were hard, I just escaped them: \`which ls\`. It took a lot of editing to get there :) –  amyassin May 25 '12 at 15:39
1  
@user946850 "To include a literal backtick character within a code span, you can use multiple backticks as the opening and closing delimiters". Source: Markdown Reference. –  Mikel May 25 '12 at 16:24
    
@amyassin: Did you add the $? –  krlmlr May 25 '12 at 16:34

Typing the command in uppercase seems to work, like LS, though I'm not really sure why.

share|improve this answer
3  
In which shell, which operating system, which terminal, etc.? –  Mikel May 24 '12 at 23:32
    
@Mikel There is a package "sl" that provides "sl" as "ls". The tips bash gives in Ubuntu also say that "LS" is provided by "sl". –  Izkata May 25 '12 at 0:18
    
This is bash 4 (installed with Fink) in Mac OS X 10.7. It also works for other commands that I have aliased like rm and grep. –  asmeurer May 25 '12 at 2:34
3  
It's just a joke :) from the mn page: LS - display animations aimed to correct users who accidentally enter LS instead of ls. –  amyassin May 25 '12 at 9:29
3  
I think this works for Mac OS X because its filesystem is case-insensitive by default. It won't work on other unixes. –  Jander May 25 '12 at 13:30

Personally, I just avoid defining aliases with the same names as commands, so ls always invokes the actual command. I have aliases or functions for various combinations of options like l, ll, and lg. (This means I need unalias ls in my .bashrc or .cshrc.)

I find that the OS's assumptions about which options I might prefer (overriding the assumptions of the designers of the ls command itself) rarely match my own personal tastes. I happen to dislike the look of ls --color=auto, and its legibility can vary greatly between black-on-white and white-on-black.

YMMV, and the other solutions are of course still good to know.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.