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