如何使用Dir在Windows命令行中导航,列出文件和目录?
如何使用Dir在Windows命令行中导航,列出文件和目录?
如何使用Dir在Windows命令行中导航,列出文件和目录?Windows operating system provides command line tool named MS-DOS. This command line have different tools and capabilities for daily operations. We will look some simple steps about usage like navigation, list files and directories etc. We will mainly use dir
command for this tutorial.
Windows操作系统提供了名为MS-DOS的命令行工具。 该命令行具有用于日常操作的不同工具和功能。 我们将介绍一些有关用法的简单步骤,如导航,列表文件和目录等。在本教程中,我们将主要使用dir
命令。
帮帮我 (Help)
Help information about dir
command can be listed like below.
可以如下列出有关dir
命令的帮助信息。
$ dir /?

更改驱动器(Change Drive)
Windows operating systems generally uses drive names for different partitions or disks. Most common usage of drive is splitting disk into two part and setting their name as C:
and D:
. If we have a CD-ROM we will also have a drive named E:
. Changin the command prompt path between these drives can be done by issuing drive names into command line.
Windows操作系统通常将驱动器名称用于不同的分区或磁盘。 驱动器最常见的用法是将磁盘分为两部分,并将其名称设置为C:
和D:
如果我们有CD-ROM,我们还将有一个名为E:
的驱动器。 可以通过在命令行中输入驱动器名称来更改这些驱动器之间的命令提示符路径。
In this example we will change drive to D:
with the same command.
在此示例中,我们将使用相同的命令将驱动器更改为D:
:。
$ D:
Or change drive to C: back again with command C:
或使用命令C:
将驱动器更改为C:
$ C:
导航上层目录 (Navigate Upper Directory)
Windows file system NTFS uses hierarchical structure for storing directories and files. In order to access upper directories and files we need to change the command line path with cd ..
command to the upper directory.
Windows文件系统NTFS使用分层结构来存储目录和文件。 为了访问上层目录和文件,我们需要使用cd ..
command更改命令行路径到上层目录。
$ cd ..

浏览所选目录(Navigate Selected Directory)
Another mostly used navigation is changing command prompt directory into a child directory. We will use cd
command with the directory name where we want to navigate. In this example we will navigate into directory named Users
.
另一个最常用的导航是将命令提示符目录更改为子目录。 我们将使用cd
命令以及要导航的目录名称。 在此示例中,我们将导航到名为Users
目录。
$ cd Users

列出文件和文件夹(List Files and Folders)
Current working directory files, folders and folders can be listed with the dir
command. We will do not provide any parameter.
可以使用dir
命令列出当前的工作目录文件,文件夹和文件夹。 我们将不提供任何参数。
$ dir

This command listed all files and directories with their date time and type information.
该命令列出了所有文件和目录及其日期时间和类型信息。
LEARN MORE How To Copy Files and Backup With Xcopy In Windows? 了解更多如何在Windows中使用Xcopy复制文件和备份?仅列出目录 (List Only Directories)
In previous command we have listed all files, folders and directories but how can we only list directories. We will provide directory attribute with /A:D
option.
在上一个命令中,我们列出了所有文件,文件夹和目录,但是如何仅列出目录。 我们将为目录属性提供/A:D
选项。
$ dir /A:D

仅列出文件(List Only Files)
Another use case for dir command is listing only files. We will list only files with /A:-D
option like below. This option actually negates so this will list non directories which is equal to files.
dir命令的另一个用例是仅列出文件。 我们将仅列出带有/A:-D
选项的文件,如下所示。 该选项实际上是无效的,因此它将列出与文件相等的非目录。
$ dir /A:-D

仅列出隐藏文件(List Only Hidden Files)
Hidden files are designed to be used by operating system. Users do not need these files to navigate, operate. This files generally holds cache or temporary values. We will use /A:H
for list hidden files.
隐藏文件旨在供操作系统使用。 用户不需要这些文件即可导航,操作。 此文件通常包含缓存或临时值。 我们将使用/A:H
列出隐藏文件。
$ dir /A:H

The hidden files listing output provides information like date time and files type like DIR
and JUNCTION
隐藏的清单文件输出提供诸如日期时间之类的信息以及诸如DIR
和JUNCTION
类的文件类型
列出时按名称排序(Sort By Name While Listing)
Sorting is very useful feature while looking specific directories and files. Files, folders and directories can be sorted with /O:N
option like below.
查找特定目录和文件时,排序是非常有用的功能。 可以使用/O:N
选项对文件,文件夹和目录进行排序,如下所示。
$ dir /O:N

反向排列时按名称排序(Sort By Name While Listing In Reverse Order)
We can list files, folders and directories alphabetically in reverse order. This start from z
to sort. We will use /O:-N
我们可以按相反的顺序按字母顺序列出文件,文件夹和目录。 这从z
开始排序。 我们将使用/O:-N
$ dir /O:-N

按大小排序,从小到大列出(Sort By Size While Listing From Smallest To Bigger)
Files can be listed according to their sizes with the /O:S
. This will start from smallest file and continue to bigger file.
可以根据文件的大小使用/O:S
列出它们。 这将从最小的文件开始,然后继续到更大的文件。
$ dir /O:S

按大小排序,从大到小列出(Sort By Size While Listing From Bigger To Smallest)
We can reverse the default sorting according to size. We will sort from bigger to the smallest with the /O:-S
我们可以根据大小反转默认排序。 我们将使用/O:-S
从大到小进行排序/O:-S
$ dir /O:-S

按上市日期排序(Sort By Date By Listing)
Files, folders and directories can be listed according to their creation date with the /O:D
.
可以使用/O:D
根据文件,文件夹和目录的创建日期列出它们。
$ dir /O:D

显示文件的所有者(Display Owner Of The File)
File, folders and directory owners can be listed and printed to the command line with /Q
option.
可以列出文件,文件夹和目录所有者,并使用/Q
选项将其打印到命令行。
$ dir /Q

In the output we will see the user and user domain or local system information.
在输出中,我们将看到用户和用户域或本地系统信息。
递归显示 (Display Recursively)
How can we list files, folders and folders deeper than current directory. We want to list all child file and folders and theirs childs up to end too. This is called recursive listing. We will use /S
option to list all files and folder recursively.
我们如何列出比当前目录更深的文件,文件夹和文件夹。 我们也要列出所有子文件和文件夹,以及它们的所有子项。 这称为递归列表。 我们将使用/S
选项来递归列出所有文件和文件夹。
$ dir /S

显示创建时间(Display Creation Time)
Creation time of the files, folder and directories can be listed with the /T:C
option like below.
可以使用/T:C
选项列出文件,文件夹和目录的创建时间,如下所示。
$ dir /T:C

显示上次访问时间(Display Last Access Time)
Last access time to the files, folder and directories can be /T:A
option.
对文件,文件夹和目录的最后访问时间可以是/T:A
选项。
$ dir /T:A

显示上次写入时间(Display Last Written Time)
Las written time shows what is the last change time of the file or directory. We will use /T:W
原始时间显示文件或目录的最后更改时间。 我们将使用/T:W
$ dir /T:W

翻译自: https://www.poftut.com/how-to-navigate-list-files-and-directories-in-windows-command-line-with-dir/
如何使用Dir在Windows命令行中导航,列出文件和目录?相关教程
-
企业级用户画像:基于USG模型使用决策树开发用户购物性别
企业级用户画像:基于USG模型使用决策树开发用户购物性别 絮叨两句: 博主是一名数据分析实习生,利用博客记录自己所学的知识,也希望能帮助到正在学习的同学们 人的一生中会遇到各种各样的困难和折磨,逃避是解决不了问题的,唯有以乐观的精神去迎接生活的挑战
-
如何在Windows中使用Schtasks从命令行计划任务?
如何在Windows中使用Schtasks从命令行计划任务? Recurring tasks are generally schedules with scheduled task manager. Scheduled task manager have GUI for management but creating a task in 20 different servers is very hard and trivial job. Wind
-
如何在Windows中使用Xcopy复制文件和备份?
如何在Windows中使用Xcopy复制文件和备份? Windows provides very featureful command which is used to copy files can take backups named xcopy . Xcopy can be used copy files from one partition to other partition or a usb drive. Xcopy also suppo
-
mysql命令行导入导出_如何在Windows中通过命令行添加,删除,删
mysql命令行导入导出_如何在Windows中通过命令行添加,删除,删除,导入,导出,管理注册表项?... mysql命令行导入导出 Registry is a database used by Windows operating systems to store information about applications, users, operating system, netw
-
使用Windows At Command计划作业和任务
使用Windows At Command计划作业和任务 Linux have the same command for same reasons to schedule commands and jobs for specified times and periods. Windows have the same command with similar usage too. Alternative to this command is schtasks c
-
如何使用Netsh命令从命令行管理Windows防火墙?
如何使用Netsh命令从命令行管理Windows防火墙? Windows firewall is a useful mechanism which is used to control network traffic and ports. There are different ways to manage Windows firewall like GUI, Powershell and MS-DOS. Today we will look
-
wmic cpu_如何在Windows中使用Wmic命令获取CPU信息?
wmic cpu_如何在Windows中使用Wmic命令获取CPU信息? wmic cpu Wmic is a set of tools used to get and set operating system related configuration and information. In this tutorial we will look how to get information about CPU. Wmic是用于获取和设
-
windows读取文件命令_如何在命令行中读取和筛选Windows Update登
windows读取文件命令_如何在命令行中读取和筛选Windows Update登录 windows读取文件命令 Windows operating systems updates generally done automatically and prompting the installation and restart of the system. All these update operations creates