Dir command is one of the most used Windows command. Dir is used mainly to list files and directories in Windows operating systems. In this tutorial we will look different usage examples of the dir command.
List Files and Folders
Without providing any option and parameter we will list all files and folder in the current working path. 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
Bare format will only provide file 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 behaivour is listing only current working directory. Listing sub directories 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 expression or similar glob presentation. One of the most used wanted situation 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
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 those have tagged as system file as 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 Created Time
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