Ubuntu – Difference between ‘dir’ and ‘ls’ terminal commands

command linecoreutilsdirectoryls

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 in 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?

Best Answer

dir and ls are part of coreutils and dir is almost the same as ls, just with different default options.

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.