dir (directory,目录)是一个条列档案目录命令行界面指令,在CP/MVMSDOSOS/2SingularityMicrosoft Windows操作系统中都有此指令。

dir指令基本上会列出目录中的档案及子目录的名称,也可以列出其档案大小,建立时间等相关资讯,并且列出所在的磁盘机、可用空间等资讯。dir指令也可以寻找其档案名称符合特定条件的档案。

用法范例

编辑

以下的范例是在Windows 7中给dir指令,没有指令列引数时的输出:

 C:\Users\Public\Pictures\Sample Pictures>dir
  Volume in drive C is System
  Volume Serial Number is C8D0-76E2
 
  Directory of C:\Users\Public\Pictures\Sample Pictures
 
 14-07-2009  06:41    <DIR>          .
 14-07-2009  06:41    <DIR>          ..
 14-07-2009  06:52           879,394 Chrysanthemum.jpg
 14-07-2009  06:52           845,941 Desert.jpg
 14-07-2009  06:52           595,284 Hydrangeas.jpg
 14-07-2009  06:52           775,702 Jellyfish.jpg
 14-07-2009  06:52           780,831 Koala.jpg
 14-07-2009  06:52           561,276 Lighthouse.jpg
 14-07-2009  06:52           777,835 Penguins.jpg
 14-07-2009  06:52           620,888 Tulips.jpg
                8 File(s)      5,837,151 bytes
                2 Dir(s)  57,925,980,160 bytes free
 
 C:\Users\Public\Pictures\Sample Pictures>dir /w
  Volume in drive C is System
  Volume Serial Number is C8D0-76E2
 
  Directory of C:\Users\Public\Pictures\Sample Pictures
 
 [.]                 [..]                Chrysanthemum.jpg   Desert.jpg          Hydrangeas.jpg      Jellyfish.jpg
 Koala.jpg           Lighthouse.jpg      Penguins.jpg        Tulips.jpg
                8 File(s)      5,837,151 bytes
                2 Dir(s)  57,925,992,448 bytes free
 
 C:\Users\Public\Pictures\Sample Pictures>

选项及指令列引数

编辑

以下是Microsoft Windows下,dir指令的选项及指令列引数

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

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

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
               H  Hidden files               A  Files ready for archiving
               S  System files               I  Not content indexed files
               L  Reparse Points             -  Prefix meaning not
  /B          Uses bare format (no heading information or summary).
  /C          Display the thousand separator in file sizes.  This is the
              default.  Use /-C to disable display of separator.
  /D          Same as wide but files are list sorted by column.
  /L          Uses lowercase.
  /N          New long list format where filenames are on the far right.
  /O          List by files in sorted order.
  sortorder    N  By name (alphabetic)       S  By size (smallest first)
               E  By extension (alphabetic)  D  By date/time (oldest first)
               G  Group directories first    -  Prefix to reverse order
  /P          Pauses after each screenful of information.
  /Q          Display the owner of the file.
  /R          Display alternate data streams of the file.
  /S          Displays files in specified directory and all subdirectories.
  /T          Controls which time field displayed or used for sorting timefield.
               C  Creation
               A  Last Access
               W  Last Written
  /W          Uses wide list format.
  /X          This displays the short names generated for non-8dot3 file names.  The format is that of /N with the
              name inserted before the long name.  If no short name is present, blanks are displayed in its place.
  /4          Displays four-digit years.

选项可以放在DIRCMD环境变数中,若要关闭现有的设定,可以在选项前加上-,例如/-W。 [1]

dir不是Unix指令,Unix有类似的指令ls,不过GNU/Linux操作系统中有dir指令,等效于ls -C -b[2]

相关条目

编辑

参考资料

编辑
  1. ^ Windows 7
  2. ^ dir invocation (GNU coreutils) at www.gnu.org