Dir (DOS command)

From Wikipedia, the free encyclopedia

This article is on the DOS command. For other uses of Dir, see the disambiguation page.

In computer software, specifically the command line interface (CLI) of the DOS operating system, dir is a command used for file and directory listing. It is analogous to the Unix ls command.

dir has existed as a DOS command since the initial release of MS-DOS. It is built in to the DOS command shell; in contrast, ls is a standalone program.

DIR displays a list of files and subdirectories in a directory.

Contents

[edit] Syntax

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] 
[/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[edit] Explanation

 [drive:][path][filename]
             Specifies drive, directory, and/or files to list.

Usage:

C:\>dir help.txt Shows if the file exists on drive c:\. C:\>dir windows Shows the content of the folder Windows if it is located in C:\ C:\>dir d:\windows Shows the content of the folder d:\Windows if it exists

In Windows XP, dir checks for switches in the %dircmd% environment variable.

[edit] Options

Particular implementations of the DOS operating system may provide more options; these are only the most common.

  • /w : Wide list format
  • /p : Pause at every page
  • /s : Also look in subdirectories
  • /a[xx] : Display files with the specified attributes (options may be combined, such as /arh, to show read-only, hidden files)
  • /o[xx] : Modifies sort order (options may be combined, such as /ons, to sort name first then size)

Attribute options:

  • /aa : Display files with Archive attribute
  • /ar : Display files with Read-Only attribute
  • /as : Display files with System attribute
  • /ah : Display files with Hidden attribute
  • /a-a : Display files without Archive attribute
  • /a-r : Display files without Read-Only attribute
  • /a-s : Display files without System attribute
  • /a-h : Display files without Hidden attribute

Sorting options:

  • /on : Sort on Name order
  • /od : Sort on Date order
  • /oe : Sort on Extension order
  • /og : Sort on Directory order
  • /os : Sort on Size order
  • /o-n : Reverse Sort on Name order
  • /o-d : Reverse Sort on Date order
  • /o-e : Reverse Sort on Extension order
  • /o-g : Reverse Sort on Directory order
  • /o-s : Reverse Sort on Size order

[edit] Output

There are several output types.

dir Displays the content of drive C:\ on the screen.
dir > sample.txt Creates a text file called sample.txt containing the content of drive C:\
dir >> sample.txt Appends the content of drive C:\ to the existing file sample.txt
dir > lpt1 Prints the content of drive C:\ onto the printer connected to LPT1

[edit] More commands

dir d: Displays the content of drive D:\
dir d: /a /s Displays the content of drive D:\ including hidden files and sub folders
dir d: /a /s Displays the content of drive D:\ including hidden files and sub folders
dir, Displays the content of the current directory including hidden files and sub folders (this functionality has been broken in recent versions of Windows).
help Displays an overview of the commands
help dir Explains the DIR command particularly

[edit] Sample listing

This sample is taken from a Windows XP implementation of the MS-DOS CLI.

C:\>dir
 Volume in drive C is Eduard Laguit
 Volume Serial Number is 2326-30E6
 
 Directory of C:\
 
11/17/2001  09:40p             257,787 INF000.SWP
04/16/2002  10:12p                 446 VIRUSLOG.TXT
05/19/2002  04:34p      <DIR>          filelib
11/22/2001  05:17p                 228 BOOT.BAD
11/22/2001  05:10p               1,663 MSDOS.BAD
12/09/2001  09:07a               8,681 SCANDISK.LOG
11/22/2001  05:40p               1,775 MSDOS.SYS
01/03/2002  12:05a      <DIR>          eBooks
11/22/2001  04:59p                 185 BOOT.w98
11/22/2001  05:12p                 253 BOOT.w2k
03/08/2002  02:08p      <DIR>          WINNT
11/22/2001  02:17p      <DIR>          GamesofEduard
11/17/2001  10:04p      <DIR>          Documents and Settings
05/12/2002  05:57p      <DIR>          dostemp
10/14/2001  09:51a      <DIR>          Downloads
08/01/2002  07:15p                 160 AUTOEXEC.BAT 
12/09/2001  05:24p      <DIR>          Backup
10/14/2001  09:25a      <DIR>          MSDOS7
09/30/2002  03:48p      <DIR>          cygwin
11/25/2002  03:02a      <DIR>          My Documents
03/08/2002  02:45p      <DIR>          Program Files
03/31/2002  07:41p      <DIR>          Temp
              9  File(s)      2,674,060 bytes
              16 Dir(s)   2,672,476,160 bytes free
In other languages