Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Whats the difference between commands:-

  1. ls
  2. \ls

So if i write

$ls
or 
$\ls

Whats the difference?

share|improve this question

2 Answers 2

up vote 7 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? –  shadyabhi 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. –  shadyabhi 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. –  shadyabhi Feb 23 '10 at 16:07
    
+1 Well spotted. –  sblair Feb 24 '10 at 0:07

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.