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.

I have compared the man pages of dir and ls and they seem to be exactly the same. Both are part of GNU coreutils and "list directory contents".

The only difference I've seen so far is that dir doesn't colorize the output.

So why do two commands exist? Is there a difference I missed? Why would one prefer dir over ls?

share|improve this question
1  
One wouldn't! Ever! –  Bananguin Oct 9 '12 at 21:50

2 Answers 2

up vote 8 down vote accepted

I would be inclined to think that dir is there just for backwards compatibility.

From GNU Coreutils:

dir is equivalent to ls -C -b; that is, by default files are listed in columns, sorted vertically, and special characters are represented by backslash escape sequences.

By the way, ls doesn't colorize the output by default: this is because most distros alias ls to ls --color=auto in /etc/profile.d. For a test, type unalias ls then try ls: it will be colorless.

share|improve this answer

dir isn't a Unix standard command but probably just a kind of alias/clone to provide some familiarity with Windows (DOS) users (and possibly VAX-VMS and other OSes where dir was used to list files).

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.