Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Whats the difference between commands:-

  1. ls
  2. \ls

So if i write

$ls
or 
$\ls

Whats the difference?

share|improve this question
up vote 9 down vote accepted

The backslash will force the ls command to be used without any aliasing.

share|improve this answer
    
+1 That would make sense – Draemon Feb 23 '10 at 15:23
    
pls tell a bit about aliasing. Whats aliasing actually? – Abhijeet Rastogi Feb 23 '10 at 15:26
    
An explanation of aliasing may warrant a new question, but here are some useful aliases superuser.com/questions/7083/useful-command-line-aliases and the Wikipedia explanation en.wikipedia.org/wiki/Alias_%28command%29 – heavyd Feb 23 '10 at 15:40
    
@Shadyabhi An alias is a short string that has been defined as a convenient short-cut for a longer command. E.g., ls may normally be an alias for ls --color, which is generally more useful than ls's normal behaviour. The MAN page documents the alias command: ss64.com/bash/alias.html – sblair Feb 23 '10 at 15:41
    
thanx for pointing out that "ls --color" thing. I was just about that thing too.. Thanx.. nicely put. – Abhijeet Rastogi Feb 23 '10 at 16:06

In general, backslash suppresses expansion, except, confusingly, where it does C-like escaping of control characters.

In the first part of your question, sblair is right, the backslash suppresses aliasing, or alias expansion..

In the second part, the backslash suppresses dollar-expansion: $ls expands to the current value of the ls shell variable, whilst $\ls is not expanded. So if ls is not set to anything, echo $ls; echo $\ls will print a blank line (the contents of $ls) followed by $ls on the next line.

share|improve this answer
    
thanx. short and precise. – Abhijeet Rastogi Feb 23 '10 at 16:07
    
+1 Well spotted. – sblair Feb 24 '10 at 0:07

You must log in to answer this question.

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