The dir command is one of the most useful commands while navigating the command line, and is present in its different forms in several operating systems. In this article, we will look at the Dir command and learn several use cases for it.
What is the dir Command
dir command in Windows OS is a built-in function that allows the user to do the following task:
- View the contents of any directory
- Check file attributes (both hidden and read-only)
- Filter search results based on date or file type.
Basic Syntax
The general syntax of the dir command is:
dir [path] [options]
- Path: specifies the location
- Options: modifies to filter the output
1. List Files & Directories
This command is used to list all files and directories in the current one:
help dir

help dir command
Output :
Displays a list of files and subdirectories in a directory.
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 O Offline files
- Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
.
.

output
Usage explanation:
The command is mainly used for displaying the list of files and subdirectories in a directory. This could be done by executing the Dir command without any arguments.
Dir

dir
Which would produce an output similar to this.
Output
Directory of C:\Users
09/26/2020 11:34 AM <DIR> .
09/26/2020 11:34 AM <DIR> ..
09/02/2020 07:07 PM 1, 000 applese
09/24/2020 08:59 PM <DIR> Public
10/20/2020 06:39 PM <DIR> Soap
1 File(s) 1, 000 bytes
4 Dir(s) 13, 879, 459, 840 bytes free

Output
2. List Content of a Specific Directory
The output of the dir command in this enable users to specify a directory to view its contents. The syntax for this command is as follows:
Input
dir C:\Users\gfg19310\Documents

List all content – Input
Output
Directory of C:\Users\gfg19310\Documents
20-03-2023 13:02 <DIR> .
20-03-2023 13:02 <DIR> ..
20-03-2023 13:02 <DIR> Custom Office Templates

List all content – Output
3. Show Hidden Files
Here, we will use /A option with the H attribute to include hidden files along with it. Here’s the syntax:
Input
dir /A:H

show hidden file – Input
Output
07-06-2023 16:36 <DIR> AppData
07-06-2023 16:36 <JUNCTION> Application Data [C:\Users\GFG19310.GFG\AppData\Roaming]
07-06-2023 16:36 <JUNCTION> Cookies [C:\Users\GFG19310.GFG\AppData\Local\Microsoft\Windows\INetCookies]
07-06-2023 16:36 <JUNCTION> Local Settings [C:\Users\GFG19310.GFG\AppData\Local]
07-06-2023 16:36 <JUNCTION> My Documents [C:\Users\GFG19310.GFG\Documents]
07-06-2023 16:36 <JUNCTION> NetHood [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
11-12-2024 05:46 3,670,016 NTUSER.DAT
07-06-2023 16:36 688,128 ntuser.dat.LOG1
07-06-2023 16:36 1,085,440 ntuser.dat.LOG2
02-01-2025 10:40 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.0.regtrans-ms
18-12-2024 09:56 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.1.regtrans-ms
18-12-2024 09:56 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.2.regtrans-ms
18-12-2024 09:56 65,536 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.blf
07-06-2023 16:36 65,536 NTUSER.DAT{53b39e88-18c4-11ea-a811-000d3aa4692b}.TM.blf
07-06-2023 16:36 524,288 NTUSER.DAT{53b39e88-18c4-11ea-a811-000d3aa4692b}.TMContainer00000000000000000001.regtrans-ms
07-06-2023 16:36 524,288 NTUSER.DAT{53b39e88-18c4-11ea-a811-000d3aa4692b}.TMContainer00000000000000000002.regtrans-ms
07-06-2023 16:36 20 ntuser.ini
07-06-2023 16:36 <JUNCTION> PrintHood [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Printer Shortcuts]
07-06-2023 16:36 <JUNCTION> Recent [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Recent]
07-06-2023 16:36 <JUNCTION> SendTo [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\SendTo]
07-06-2023 16:36 <JUNCTION> Start Menu [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Start Menu]
07-06-2023 16:36 <JUNCTION> Templates [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Templates]

show hidden file – Output
4. List Files with Specific Extensions
To display files with a specific extension (e.g., .txt): Here’s a sample
Input
dir *.txt

Display Text -input
Output
Directory of C:\Users\GFG19310.GFG
14-11-2024 15:32 3 example.txt
20-11-2024 14:44 0 filename.txt
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt

Display Text -Output
5. View Subdirectories
To include all subdirectories and their contents, use the following command:
Input
dir /S

dir /S
Output
Directory of C:\Users\GFG19310.GFG\Saved Games
07-06-2023 16:36 <DIR> .
07-06-2023 16:36 <DIR> ..
0 File(s) 0 bytes
Directory of C:\Users\GFG19310.GFG\Searches
07-06-2023 16:38 <DIR> .
07-06-2023 16:38 <DIR> ..
08-11-2022 16:52 855 winrt--{S-1-5-21-1623517014-2252875782-278851815-1404}-.searchconnector-ms
07-06-2023 16:37 859 winrt--{S-1-5-21-2245693176-3959787992-2909979321-1244}-.searchconnector-ms
2 File(s) 1,714 bytes
Directory of C:\Users\GFG19310.GFG\Videos
07-06-2023 16:38 <DIR> .
07-06-2023 16:38 <DIR> ..
26-12-2024 13:37 <DIR> Captures
0 File(s) 0 bytes
Directory of C:\Users\GFG19310.GFG\Videos\Captures
26-12-2024 13:37 <DIR> .
26-12-2024 13:37 <DIR> ..
26-12-2024 13:37 185,053 File Explorer 26-12-2024 13_37_47.png
11-10-2023 15:51 23,668 Network Connections .png

Fetching Directory
6. Sort by Date, Size, or Name
We can fetch data based on date, size or name. Let’s check them out:
By Date:
Input
dir /O:D

dir /O:D
Output
Directory of C:\Users\GFG19310.GFG
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
07-06-2023 16:36 <DIR> Favorites
07-06-2023 16:36 <DIR> Music
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:36 <DIR> Links
07-06-2023 16:37 <DIR> OneDrive
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos
07-06-2023 16:40 <DIR> Documents
18-04-2024 12:51 2,635,835 get-pip.py
18-04-2024 16:16 2,635,835 get-pip.p
14-11-2024 15:32 3 example.txt
14-11-2024 15:35 3 Rqapture.txt
20-11-2024 14:44 0 filename.txt
20-11-2024 14:45 0 Rapture.txt
12-12-2024 18:45 <DIR> my-node-project
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
26-12-2024 10:02 <DIR> Downloads
30-12-2024 18:34 <DIR> Pictures
31-12-2024 16:02 <DIR> Desktop

Output
By Size:
Input
dir /O:S

dir /O:S
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Videos
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:32 3 example.txt
14-11-2024 15:35 3 Rqapture.txt
18-04-2024 12:51 2,635,835 get-pip.py
18-04-2024 16:16 2,635,835 get-pip.p

Output
By Name:
Input
dir /O:N

dir /O:N
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2,635,835 get-pip.p
18-04-2024 12:51 2,635,835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos

Output
7. View Results Page by Page
This command is used where too many files exists, we can use the /P option to get results one page at a time. Here’s the command:
Input
dir /P

dir /P
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2,635,835 get-pip.p
18-04-2024 12:51 2,635,835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos

Output
8. List File Attributes
We can also include attributes such as read-only files and archives using the following command:
Input
dir /A

dir /A
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> AppData
07-06-2023 16:36 <JUNCTION> Application Data [C:\Users\GFG19310.GFG\AppData\Roaming]
07-06-2023 16:36 <DIR> Contacts
07-06-2023 16:36 <JUNCTION> Cookies [C:\Users\GFG19310.GFG\AppData\Local\Microsoft\Windows\INetCookies]
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2,635,835 get-pip.p
18-04-2024 12:51 2,635,835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <JUNCTION> Local Settings [C:\Users\GFG19310.GFG\AppData\Local]
07-06-2023 16:36 <DIR> Music
07-06-2023 16:36 <JUNCTION> My Documents [C:\Users\GFG19310.GFG\Documents]
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:36 <JUNCTION> NetHood [C:\Users\GFG19310.GFG\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
11-12-2024 05:46 3,670,016 NTUSER.DAT
07-06-2023 16:36 696,320 ntuser.dat.LOG1
07-06-2023 16:36 1,003,520 ntuser.dat.LOG2
02-01-2025 10:40 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.0.regtrans-ms
18-12-2024 09:56 1,048,576 NTUSER.DAT{53b39e87-18c4-11ea-a811-000d3aa4692b}.TxR.1.regtrans-ms
18-12-2024 09:56 1,048,57 ..

Output
9. Display File Size
You can also check the file size (in bytes) using the following command:
Input
dir /-C

dir /-C
Output
Directory of C:\Users\GFG19310.GFG
18-12-2024 09:56 <DIR> .
18-12-2024 09:56 <DIR> ..
07-06-2023 16:36 <DIR> 3D Objects
07-06-2023 16:36 <DIR> Contacts
31-12-2024 16:02 <DIR> Desktop
07-06-2023 16:40 <DIR> Documents
26-12-2024 10:02 <DIR> Downloads
14-11-2024 15:32 3 example.txt
07-06-2023 16:36 <DIR> Favorites
20-11-2024 14:44 0 filename.txt
18-04-2024 16:16 2635835 get-pip.p
18-04-2024 12:51 2635835 get-pip.py
07-06-2023 16:36 <DIR> Links
07-06-2023 16:36 <DIR> Music
12-12-2024 18:45 <DIR> my-node-project
07-06-2023 16:37 <DIR> OneDrive
30-12-2024 18:34 <DIR> Pictures
20-11-2024 14:45 0 Rapture.txt
14-11-2024 15:35 3 Rqapture.txt
07-06-2023 16:36 <DIR> Saved Games
07-06-2023 16:38 <DIR> Searches
07-06-2023 16:38 <DIR> Videos

Output
Advanced Syntax
The above-mentioned syntaxes is for general usage. Now, let’s see some of the advanced usage syntax along with their examples.
10. Save Output to a File
We can redirect the output to a text file (dir command) using the syntax below:
Input (file name: rapture.txt)
dir /S > rapture.txt

dir /S > filename
Output
A file name with the provided name will be created containing the directory list.

Output
11. Search for any Specific File
You can search for any file by its name (or even partial name), following this syntax:
Input (file name: rapture – taken as a partial name “rapt”)
dir *rapt*

*filename*
Output
Directory of C:\Users\GFG19310.GFG
03-01-2025 11:03 7,854,908 Rapture.txt
1 File(s) 7,854,908 bytes
0 Dir(s) 116,168,089,600 bytes free

Output
12. Check the Total Number of Files
This syntax will summarise the total count of a file including directory:
Input
dir /W

dir /W
Output

Output
Bonus: Useful cmd Options (Summarization)
Option |
Description |
/P |
Fetch results one page at a time |
/S |
Includes all files in subdirectories. |
/A |
Displays files with specified attributes (e.g., /A:H for hidden files). |
/O |
Sorts output (e.g., /O:D for date, /O:N for name). |
/B |
Displays output in bare format (file names only, without additional details). |
/L |
Displays names in lowercase. |
/T |
Displays time attributes (e.g., /T:C for creation time). |
/Q |
Displays file ownership information. |
The dir command is vastly used among users for managing and exploring directories through different ways and patterns in Windows OS. You can give it all a try and organize your work smoothly.
Similar Reads
cmd | Rem command
Rem (abbreviation of remark) is a command (internal) found inside the Windows Command Processor Command Prompt, that allows for inclusion of comments inside batch programs. Comments are supported by most Programming languages usually via special syntax that is associated to them. Ex. Python using po
3 min read
move cmd command
The move is an internal command found in the Windows Command Interpreter (cmd) that is used to move files and folders/directories. The command is robust than a regular move operation, as it allows for pattern matching via the inclusion of Wildcards in the source path. The command is a very generic o
5 min read
Cd cmd command
Cd is the abbreviation or synonym for chdir. It is a command found inside the Windows Command Processor (cmd) that allows for change of the current working directory of a shell instance. The CWD (Current Working Directory) is a path (of a directory) inside the file system, where the shell is current
3 min read
Useful CMD Commands for Daily Use in Windows OS
The Windows Command Prompt (CMD) is a powerful tool that many users overlook, but knowing a few useful CMD commands for Windows can make your daily tasks much more efficient. From navigating the file system to managing network settings, these daily use CMD commands can help streamline your workflow
3 min read
How to Change Directories in Command Prompt?
In this article, let's learn how to navigate through directories in Command Prompt - The Command Prompt (CMD) in Windows is a powerful tool for executing commands, managing files, and navigating your system. One of the most common tasks youâll perform in CMD is changing directories, which allows you
12 min read
39 Windows CMD Commands for Everyone (2025 Updated)
The Windows Command Prompt (CMD) is a powerful tool that allows users to interact with their operating system through text-based commands. Whether you're a beginner exploring CMD for the first time, an expert troubleshooting advanced issues, or just looking for utility-focused tasks, this guide has
12 min read
How to Use Command Prompt - Windows Command Prompt Guide
Learn how to manually run the Command Prompt in different versions of Windows - The Windows Command Prompt (CMD) is a powerful tool that allows users to execute commands, automate tasks, and troubleshoot system issues efficiently. Whether youâre a beginner looking to learn basic CMD commands or an a
5 min read
How to Create a File in CMD
We all know that one can easily create files using GUI options, but what if you can use a faster way to create files through the command-line interface? This is not a necessary but useful skill for anyone working with Windows. Whether you're automating tasks, working on scripts, or preferring using
5 min read
How to Search Files using CMD?
Ever lost a file on your computer and wished there was a quick way to find it without clicking through endless folders? Say hello to the Windows Command Prompt (CMD) a powerful little tool that can help you search for files fast. In this how-to blog, we will explore the steps to search for files usi
5 min read
How to Run an exe through CMD?
Running any software on Windows is quite easy, but what if you have to run any.exe file using the CMD? The Command Prompt in Windows is a powerful, versatile tool that grants users direct access to the operating systemâs core functionalities. While graphical interfaces (GUIs) simplify many tasks. In
6 min read