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.
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.
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
$ 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.
$ 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.
$ dir *.txt
List JPEG Files
We can list jpeg files with the following command.
$ dir *.jpeg
List Excel (xls) Files
We can list Excel files with the following command.
$ dir *.xls
List Word (doc) Files
We can list Word files with the following command.
$ 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;
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 .
$ 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
$ dir /A:R
List Hidden Files
Hidden files can be listed with the
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
$ 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.
$ dir /Q
List Create Time of Files and Folders
The file creation time can be listed with the
$ dir /TC
List Last Accessed Time
Files are accessed during time these access time can be printed with the /
TA option like below.
$ dir /TA
Find Last Modified Time
Last modified time of the file can be listed with the /
$ dir /TW