Monday, May 6, 2024
83
rated 0 times [  83] [ 0]  / answers: 1 / hits: 91503  / 2 Years ago, fri, july 1, 2022, 10:32:30

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?


More From » command-line

 Answers
5

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.


[#40399] Friday, July 1, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
poous

Total Points: 81
Total Questions: 101
Total Answers: 119

Location: Cambodia
Member since Sat, Oct 3, 2020
4 Years ago
;