{{Short description|Shell command for listing files and directories}} {{Other uses|Dir (disambiguation)}} {{Lowercase title}} {{Infobox software | name = dir | logo = | screenshot = SpartaDOS X prompt.png | screenshot size = | caption = The SpartaDOS X <code>DIR</code> command | developer = DEC, DR, Intel, Cromemco, MetaComCo, Microsoft, IBM, Datalight, ICD, Inc. | released = | latest release version = | latest release date = | operating system = CP/M, MP/M, ISIS-II, iRMX 86, CDOS, TRIPOS, DOS, MSX-DOS, SISNE plus, 4690 OS, PC-MOS, OS/2, Windows, Singularity, ReactOS, AROS, VMS, RT-11, RSX-11, OS/8, AmigaDOS | platform = Cross-platform | genre = Command | license = CP/M, MP/M: BSD-like<br />MS-DOS: MIT<br />PC-MOS: GPL-3.0-only<br />ReactOS: GPL | website = }} '''<code>dir</code>''', short for ''directory'', is a shell command for listing file system contents: files and directories.<ref>{{cite book|url=http://archive.org/details/1988-rugheimer-spanik-amigados-quick-reference|title=AmigaDOS quick reference|first1=Hannes|last1=Rügheimer|first2=Christian|last2=Spanik|date=October 22, 1988|publisher=Grand Rapids, Mi : Abacus|isbn=9781557550491|via=Internet Archive}}</ref> Arguably, the command provides the same essential functionality as the <code>ls</code> command, but typically the two commands are described as notably separate concepts, possibly since {{code|ls}} is implemented from a codebase that shares more history than many {{code|dir}} implementations.

The command is often implemented as internal in the operating system shell instead of as a separate application as many other commands are.

==Variants== [[File:Abort Retry Fail.PNG|200px|thumb|right|Screenshot showing the "Abort, Retry, Fail?" prompt on MS-DOS.]]

Although syntax, semantics and implementations vary, a {{code|dir}} command with essentially the same functionality is available in the operating systems: CP/M,<ref>{{cite web|url=http://www.cpm.z80.de/manuals/cpm22-m.pdf |title=Operating manual |publisher=cpm.z80.de |access-date=2019-10-22}}</ref> MP/M,<ref name="MP/M_1981_UG">{{cite book |author=Digital Research |author-link=Digital Research |title=MP/M-86 Operating System - User's Guide |date=1981-09-25 |edition=1 |publisher=Digital Research |location=Pacific Grove, CA, USA |url=http://bitsavers.informatik.uni-stuttgart.de/pdf/digitalResearch/mpm-86/MPM-86_Users_Guide_Sep81.pdf |access-date=2017-01-04 |url-status=live |archive-url=https://web.archive.org/web/20170104172228/http://bitsavers.informatik.uni-stuttgart.de/pdf/digitalResearch/mpm-86/MPM-86_Users_Guide_Sep81.pdf |archive-date=2017-01-04}}</ref> ISIS-II,<ref>[http://bitsavers.org/pdf/intel/ISIS_II/9800306-06_ISIS-II_Users_Guide_May81.pdf ISIS II Users Guide]</ref> iRMX 86,<ref>[https://archive.org/details/bitsavers_inteliRMX1_19819263 iRMX 86 INTRODUCTION AND OPERATOR'S REFERENCE MANUAL For Release 6]</ref> CDOS,<ref>[http://www.hartetechnologies.com/manuals/Cromemco/CDOSv1.PDF CDOS USER'S MANUAL]</ref> TRIPOS,<ref>{{cite web|url=https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf |title=Introduction to Tripos |access-date=2019-10-22}}</ref> DOS, 4690 OS,<ref>[https://archive.org/details/4690OSV6r2UsersGuide/page/n169]{{Dead link|date=October 2019}}</ref> OS/2,<ref>{{cite web|url=http://www.jatomes.com/Help/Os2Cmd.php#DIR|title=JaTomes Help - OS/2 Commands|website=www.jatomes.com|access-date=2019-07-20|archive-date=2019-04-14|archive-url=https://web.archive.org/web/20190414130029/http://www.jatomes.com/Help/Os2Cmd.php#DIR|url-status=dead}}</ref> Windows,<ref>{{cite web|url=https://www.computerhope.com/dirhlp.htm|title=MS-DOS and Windows command line dir command|website=www.computerhope.com}}</ref> Singularity, ROM-DOS,<ref>{{Cite web|url=https://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf|title=Datalight ROM-DOS User's Guide|website=www.datalight.com}}</ref> ReactOS,<ref>{{cite web|url=https://github.com/reactos/reactos|title=GitHub - reactos/reactos: A free Windows-compatible Operating System|date=October 22, 2019|via=GitHub}}</ref> GNU,<ref>{{cite web|url=https://www.gnu.org/software/coreutils/dir|title=GNU Coreutils Manual|publisher=Free Software Foundation}}</ref> AROS,<ref>{{cite web|url=https://aros.sourceforge.net/documentation/users/shell/index.php|title=AROS Research Operating System|website=aros.sourceforge.net|access-date=2025-08-10|archive-date=2020-01-02|archive-url=https://web.archive.org/web/20200102204945/http://aros.sourceforge.net/documentation/users/shell/index.php|url-status=dead}}</ref> VMS, RT-11, RSX-11, OS/8, 86-DOS,<ref>{{cite book |title=86-DOS - Disk Operating System for the 8086 - User's Manual |edition=Preliminary |version=Version 0.3 |date=1980 |publisher=Seattle Computer Products, Inc. |location=Seattle, Washington, USA |url=http://www.patersontech.com/Dos/docs/86_Dos_usr_03.pdf |access-date=2019-07-14 |url-status=dead |archive-url=https://web.archive.org/web/20190714004434/http://www.patersontech.com/dos/docs/86_Dos_usr_03.pdf |archive-date=2019-07-14}} (59 pages)</ref> MS-DOS (in versions 1 and later),<ref name="RUNNINGMSDOS">{{Cite book|author-last=Wolverton|author-first=Van|title=Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition|date=2003|publisher=Microsoft Press|isbn=0-7356-1812-7}}</ref> and DOSBox.

Some applications also provide a {{code |dir}} command with similar functionality. The typical File Transfer Protocol (FTP) command-line client provides a <code>dir</code> command for listing a remote directory. The numerical computing environments MATLAB and GNU Octave include a <code>dir</code> command.<ref>{{cite web|url=https://www.mathworks.com/help/matlab/ref/dir.html|title=List folder contents - MATLAB dir|website=www.mathworks.com}}</ref><ref>{{cite web|url=https://octave.sourceforge.io/octave/function/dir.html|title=Function Reference: dir|website=octave.sourceforge.io}}</ref>

Generally, Unix-like systems use the {{code|ls}} command for the needs that <code>dir</code> satisfies in other types of systems. Notably, the Unix-like GNU operating system, provides a <code>dir</code> command that is equivalent to <code>ls&nbsp;-C&nbsp;-b</code>; that is, by default files are listed in columns, sorted vertically, and special characters are represented by backslash escape sequences.<ref>[//www.gnu.org/software/coreutils/manual/html_node/dir-invocation.html dir invocation] (GNU coreutils) at www.gnu.org</ref>

==Examples== [[File:Commodore C128 CPM Screenshot 2 full.jpg|200px|thumb|right|CP/M 3.0 directory listing on a Commodore 128 home computer.]] [[File:Robotron1715SCREEN.gif|200px|thumb|right|Directory listing on SCP running on a robotron PC 1715.]] [[File:J Elwro 804 Junior.JPG|200px|thumb|right|Directory listing on CP/J 2.21 running on an Elwro 804 Junior.]] [[File:Dir command in Windows Command Prompt.png|200px|thumb|right|Microsoft Windows Command Prompt showing a directory listing.]]

List all files and directories in the working directory. {{sxhl|2=doscon|C:\Users>dir}}

List text and batch files of the working directory by specifying filename extensions ".txt" or ".bat" with the "*" wildcard character that matches any base file name. {{sxhl|2=doscon|C:\Users>dir *.txt *.bat}}

List files and directories in the specified directory and any subdirectories, recursively, in wide format, pausing after each screen of output. The directory name is enclosed in double-quotes, to prevent it from being interpreted is as two separate command-line options because it contains a space. {{sxhl|2=doscon|C:\Users>dir /s /w /p "C:\Users\johndoe\My Documents"}}

List any NTFS junction points: {{pre| {{codett|2=doscon|C:\Users>dir /ash}} {{codett|2=output|Volume in drive C is OS.}} {{codett|2=output|Volume Serial Number is xxxx-xxxx}} {{codett|2=output|Directory of C:\Users}} {{codett|2=output|12/07/2019 02:30 AM <SYMLINKD> All Users [C:\ProgramData]}} {{codett|2=output|12/07/2019 02:30 AM <JUNCTION> Default User [C:\Users\Default]}} {{codett|2=output|12/07/2019 02:12 AM 174 desktop.ini}} {{codett|2=output|1 File(s) 174 bytes}} {{codett|2=output|2 Dir(s) 332,659,789,824 bytes free}}

}}

==See also== * Directory (OpenVMS command) * List of DOS commands * tree

==References== {{Reflist}}

==Further reading== *{{Cite book|author-last=Wolverton|author-first=Van|title=MS-DOS Commands: Microsoft Quick Reference, 4th Revised edition|url=https://archive.org/details/msdos00wolv|url-access=registration|date=1990|publisher=Microsoft Press|isbn=978-1556152894}} *{{Cite book|author1=Kathy Ivens|author2=Brian Proffit|year=1993|title=OS/2 Inside & Out|publisher=Osborne McGraw-Hill|isbn=978-0078818714}} *{{Cite book|first=Æleen|last=Frisch|year=2001|title=Windows 2000 Commands Pocket Reference|publisher=O'Reilly|isbn=978-0-596-00148-3}}

==External links== {{Wikibooks|Guide to Windows Commands}} *[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/dir dir | Microsoft Docs] *[https://github.com/microsoft/MS-DOS/blob/master/v2.0/source/DIR.ASM Open source DIR implementation that comes with MS-DOS v2.0] *[https://www.windows-commandline.com/dir-command-line-options/ Dir command syntax and examples]

{{Windows commands}}

Category:CP/M commands Category:Internal DOS commands Category:Microcomputer software Category:Microsoft free software Category:MSX-DOS commands Category:OS/2 commands Category:ReactOS commands Category:Windows commands Category:Windows administration