Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've been trying to find the difference between using the dir and ls commands in terminal. I know ls is the traditional unix method of viewing the files in a directory, and that dir is the windows command prompt equivalent, but both commands work in terminal.

If i type dir it displays the files and folders in the directory, and if I type ls it does the same, except with content highlighting. Both commands accept options (i.e. 'ls -a' and 'dir -a' both return all files and folders and hidden files.

So does anyone know what the difference is and why both dir and ls are used?

share|improve this question
dir --color ;) –  Rinzwind Feb 13 '12 at 18:22
just wanted to say I'm surprised at the amount of response this question has received. I guess I was not the only one wondering about this :) –  BretD Feb 24 '12 at 3:25
Commands from ancient times always drag the older nerds out of the woodwork ;) –  Rinzwind Feb 24 '12 at 8:03
add comment

3 Answers

up vote 26 down vote accepted

dir and ls are part of coreutils and dir is an alias.

The GNU Core Utilities are the basic file, shell and text manipulation utilities of the GNU operating system. These are the core utilities which are expected to exist on every operating system.

info dir says:

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.

Oh and there is also vdir! info vdir says:

vdir is equivalent to ls -l -b; that is, by default files are listed in long format and special characters are represented by backslash escape sequences.

Most likely dir exists for backwards compatibility or due to historical reasons.

share|improve this answer
I was thinking that it was probably just an alias of the other. I assumed the reasoning was to make windows users feel more at home lol Thank you for the thorough answer! –  BretD Feb 13 '12 at 19:16
type alias dir to see what it actually is. type alias to see all aliases. –  user606723 Feb 13 '12 at 19:38
@user606723 , 'alias dir' doesn't show in 11.10 (at least not for me). I believe 'alias' only shows local user alias settings, not system wide. –  James Feb 14 '12 at 23:19
The person downvoting me 1.5 years after this was made: please tell me why? –  Rinzwind Jul 24 '13 at 5:15
add comment

Short Answer : None, dir is an alias of ls, as @Rinzwind said, ls have --color by default

share|improve this answer
dir is not an alias of ls. They are separate binaries in /usr/bin that behave differently, as described in Rinzwind's answer. You could achieve this with aliases, but that is not how it is achieved. Separate dir and ls binaries appear on all systems that use GNU Coreutils. If you need proof, run cmp /bin/ls /bin/dir. –  Eliah Kagan May 28 '12 at 23:16
some time ago it was an alias and you could see it listed in the alias list just by typing alias, now a new binary is compiled for dir. You can download its code with: git clone git://git.sv.gnu.org/coreutils. Only one line of code is changed in ls-dir.c and is this: int ls_mode = LS_MULTI_COL;. Technically is not an alias, but practically it is LS but with different default options(1 line of code). –  pacofvf May 29 '12 at 15:09
Yes, dir is ls but with different default options. dir and ls have always been separate binaries in distributions that use GNU Coreutils. Some distributions may, or may have, also defined an alias called dir (defining aliases that are the same name as an existing command is pretty common). But they are separate executables. To distinguish between a shell alias (which is not a file at all) and a separate executable with similar source code, is not a pedantic distinction. It is both false and misleading to say that dir is an alias of ls in Ubuntu. –  Eliah Kagan May 29 '12 at 15:32
Yes, I agree with you, but in this case, is not similar source code, is the same source code. If we say that an alias is just anything listed in alias then of course is not an alias. –  pacofvf May 29 '12 at 15:50
It is not the same source code. As you said, "one line of source is changed." And if it were the same source then it would still not be an alias. There are lots of things in a Unix-like system that are similar to aliases but which would be vastly confusing to novices (and exasperating to experienced users) to call aliases. Symbolic links, hard links, identical files, similar files, wrapper scripts, shell builtins hiding executables, and synced files (e.g. with UbuntuOne) are all similar to aliases in significant ways, but they aren't aliases. –  Eliah Kagan May 29 '12 at 15:55
add comment

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
add comment

Your Answer


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.