Dir (command)
Shell command for listing files and directories
- 3 min read
- 2 chapters
Related on Lably
Through Command (computing), File system and Operating system
The command is often implemented as internal in the operating system shell instead of as a separate application as many other commands are.
Variants
Although syntax, semantics and implementations vary, a dir command with essentially the same functionality is available in the operating systems: CP/M, MP/M, ISIS-II, iRMX 86, CDOS, TRIPOS, DOS, 4690 OS, OS/2, Windows, Singularity, ROM-DOS, ReactOS, GNU, AROS, VMS, RT-11, RSX-11, OS/8, 86-DOS, MS-DOS (in versions 1 and later), and DOSBox.
Some applications also provide a dir command with similar functionality. The typical File Transfer Protocol (FTP) command-line client provides a dir command for listing a remote directory. The numerical computing environments MATLAB and GNU Octave include a dir command.
Generally, Unix-like systems use the ls command for the needs that dir satisfies in other types of systems. Notably, the Unix-like GNU operating system, provides a dir command that 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.
Sign in to keep reading
One more chapter is free with a Lably account.
Examples
List all files and directories in the working directory.
<span id="mwtA"></span><span class="gp" id="mwtQ">C:\Users></span><span class="k" id="mwtg">dir</span>
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.
<span id="mwvg"></span><span class="gp" id="mwvw">C:\Users></span><span class="k" id="mwwA">dir</span> *.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.
<span id="mwxw"></span><span class="gp" id="mwyA">C:\Users></span><span class="k" id="mwyQ">dir</span> /s /w /p <span class="s2" id="mwyg">"C:\Users\johndoe\My Documents"</span>
List any NTFS junction points:
<code class="tpl-codett mw-highlight mw-highlight-lang-doscon mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt73" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"doscon","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"C:\\Users>dir /ash"}}' id="mwzw"><span class="gp" id="mw0A">C:\Users></span><span class="k" id="mw0Q">dir</span> /ash</code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt74" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"Volume in drive C is OS."}}' id="mw0g"><span class="go" id="mw0w">Volume in drive C is OS.</span></code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt75" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"Volume Serial Number is xxxx-xxxx"}}' id="mw1A"><span class="go" id="mw1Q">Volume Serial Number is xxxx-xxxx</span></code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt76" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"Directory of C:\\Users"}}' id="mw1g"><span class="go" id="mw1w">Directory of C:\Users</span></code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt77" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"12/07/2019 02:30 AM <SYMLINKD> All Users [C:\\ProgramData]"}}' id="mw2A"><span class="go" id="mw2Q">12/07/2019 02:30 AM <SYMLINKD> All Users [C:\ProgramData]</span></code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt78" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"12/07/2019 02:30 AM <JUNCTION> Default User [C:\\Users\\Default]"}}' id="mw2g"><span class="go" id="mw2w">12/07/2019 02:30 AM <JUNCTION> Default User [C:\Users\Default]</span></code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt79" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"12/07/2019 02:12 AM 174 desktop.ini"}}' id="mw3A"><span class="go" id="mw3Q">12/07/2019 02:12 AM 174 desktop.ini</span></code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt80" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"1 File(s) 174 bytes"}}' id="mw3g"><span class="go" id="mw3w">1 File(s) 174 bytes</span></code> <code class="tpl-codett mw-highlight mw-highlight-lang-output mw-content-ltr" style="border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;" dir="ltr" typeof="mw:Extension/syntaxhighlight" about="#mwt81" data-mw='{"name":"syntaxhighlight","attrs":{"lang":"output","class":"tpl-codett","style":"border:none; padding: 0px 0px; color:var(--color-base, #202122); background:transparent;","inline":"1"},"body":{"extsrc":"2 Dir(s) 332,659,789,824 bytes free"}}' id="mw4A"><span class="go" id="mw4Q">2 Dir(s) 332,659,789,824 bytes free</span></code>
