
dir 列出文件清单
Dir command is one of the most used Windows commands. Dir is used mainly to list files and directories in Windows operating systems. In this tutorial, we will look at different usage examples of the dir command.
Dir命令是最常用的Windows命令之一。 Dir主要用于列出Windows操作系统中的文件和目录。 在本教程中,我们将查看dir命令的不同用法示例。
列出文件和文件夹 (List Files and Folders)
Without providing any option and parameter we will list all files and folders in the current working path. The current working path is the path where the shell currently locates. While printing files and folders there is also information like Volume name and Volume Serial Number.
在不提供任何选项和参数的情况下,我们将列出当前工作路径中的所有文件和文件夹。 当前工作路径是外壳当前所在的路径。 在打印文件和文件夹时,还有诸如卷名和卷序列号之类的信息。
$ dir

列出文件和文件夹的裸格式(List Files and Folders Bare Format)
The bare format will only provide files and folders. There will be no other information like creation date-time file type etc. We will provide the /b
option.
裸格式将仅提供文件和文件夹。 将没有其他信息,例如创建日期时间文件类型等。我们将提供/b
选项。
$ dir /b

递归列出文件(List Files Recursively)
The default behavior is listing only the current working directory. Listing subdirectories is a need some times. This can be done with /s
option like below.
默认行为是仅列出当前工作目录。 列出子目录有时是需要的。 可以使用/s
选项(如下所示)完成此操作。
$ dir /s
根据扩展名列出文件 (List Files According To Extension)
Another useful feature is listing files and directories with regular expressions or similar glob presentations. One of the most used wanted situations is listing files and folders according to their extension. In this example, we will list txt
extension by using wildcard.
另一个有用的功能是使用正则表达式或类似的glob表示形式列出文件和目录。 最常用的通缉情况之一是根据文件和文件夹的扩展名列出它们。 在此示例中,我们将使用通配符列出txt
扩展名。
$ dir *.txt

列出JPEG文件(List JPEG Files)
We can list jpeg files with the following command.
我们可以使用以下命令列出jpeg文件。
$ dir *.jpeg
列出Excel(xls)文件 (List Excel (xls) Files)
We can list Excel files with the following command.
我们可以使用以下命令列出Excel文件。
$ dir *.xls
列出Word(doc)文件 (List Word (doc) Files)
We can list Word files with the following command.
我们可以使用以下命令列出Word文件。
$ dir *.doc
文件和文件夹属性 (File and Folder Attributes)
Files and folder have attributes to provide information and store metadata about them. These attributes can be listed with dir
command by providing related options. Some attributes file and folder may have are listed below;
文件和文件夹具有提供信息并存储有关它们的元数据的属性。 通过提供相关选项,可以使用dir
命令列出这些属性。 下面列出了一些属性文件和文件夹:
- Read 读
- Write写
- Hidden隐
- Directory目录
- ……
仅列出目录 (List Only Directories)
We may need to print only directories and do not include files. This can be done with the display only directory attribute like below.
我们可能只需要打印目录而不包含文件。 这可以通过如下所示的“仅显示目录”属性来完成。
$ dir /A:D

仅列出文件(List Only Files)
We will use directory attribute but we will negate the attribute and this will only display the non directory files. We will use /A:-D
option .
我们将使用目录属性,但是将使属性无效,这将仅显示非目录文件。 我们将使用/A:-D
选项。
$ dir /A:-D

列出只读文件(List Read Only Files)
In windows systems, files can be read, write, append, etc. To protect files for changes some files are made read-only. These files can be listed by using read-only attributes with /A:R
.
在Windows系统中,可以读取,写入,追加等文件。为了保护文件不被更改,某些文件被设为只读。 可以通过对/A:R
使用只读属性来列出这些文件。
$ dir /A:R
列出隐藏文件 (List Hidden Files)
Hidden files can be listed with the /A:H
option.
可以使用/A:H
选项列出隐藏的文件。
$dir /A:H
排除只读文件 (Exclude Read Only Files)
Read only files can be excluded by negating the normal usage like below.
通过取消如下所示的常规用法,可以排除只读文件。
$ dir /A:-R
排除系统文件 (Excludes System Files)
Windows have system files that have tagged as system files as an attribute. We can exclude system files while listing with /A:-S
.
Windows具有标记为系统文件作为属性的系统文件。 当使用/A:-S
列出时,我们可以排除系统文件。
$ dir /A:-S
打印文件的详细元数据 (Print Detailed Metadata For Files)
Meta data about files and folder can be printed with /Q
option. This will also list file ownership.
可以使用/Q
选项打印有关文件和文件夹的元数据。 这还将列出文件所有权。
$ dir /Q

列出文件和文件夹的创建时间(List Create Time of Files and Folders)
The file creation time can be listed with the /TC
option.
可以使用/TC
选项列出文件创建时间。
$ dir /TC

列出上次访问时间(List Last Accessed Time)
Files are accessed during time these access time can be printed with the /TA
option like below.
在访问期间,可以使用/ TA
选项打印这些访问时间,如下所示。
$ dir /TA

查找上次修改时间(Find Last Modified Time)
Last modified time of the file can be listed with the /TW
option.
文件的上次修改时间可以使用/ TW
选项列出。
$ dir /TW

翻译自: https://www.poftut.com/windows-dir-command-tutorial-examples-list-files-file-information/
dir 列出文件清单