Displaying files in Command Prompt (cmd) is a fundamental skill for anyone working with Windows systems, whether you are troubleshooting, automating tasks, or simply navigating your file hierarchy. The built‑in dir command, combined with its numerous switches and the power of wildcards, lets you list directory contents in virtually any format you need. This guide walks you through the basics, explores advanced options, shows practical examples, and answers common questions so you can confidently view files from the command line.
Understanding the Command Prompt
Before diving into the commands, it helps to know what the Command Prompt actually is. On top of that, it interprets text commands you type and translates them into actions performed by the operating system. cmd.exe is the command‑line interpreter that ships with Windows. When you open a Command Prompt window, you are placed in a working directory—usually your user profile folder—but you can change locations with cd (change directory) and then inspect what resides there.
The primary tool for viewing files is the dir (directory) command. In practice, by itself, it prints a list of files and subfolders in the current directory, showing names, sizes, timestamps, and whether each entry is a file or a directory. Adding modifiers refines the output, filters results, or changes the sorting order No workaround needed..
Basic Commands to List Files
Simple Directory Listing
dir
Running dir without any arguments yields a classic table:
- File/folder name
- Size (in bytes)
- Last modified date and time
- Attribute column (blank for normal files,
<DIR>for folders)
Showing All Files Including Hidden and System Items
By default, dir hides files marked with the hidden or system attributes. To reveal them, add the /a switch:
dir /a
You can further specify which attributes to display:
| Switch | Meaning |
|---|---|
/a:h |
Show only hidden files |
/a:s |
Show only system files |
/a:-h |
Show files that are not hidden |
/a:d |
Show only directories |
Listing Files in Bare Format
If you need a clean list—just names, one per line—use the /b switch:
dir /b
This output is ideal for feeding into other commands or scripts because it omits size, date, and extra headers Simple, but easy to overlook..
Displaying Files in a Sorted Order
The /o switch controls sorting. Combine it with one or more of the following letters:
| Letter | Sort by |
|---|---|
n |
Name (alphabetic) |
e |
Extension |
s |
Size (smallest first) |
d |
Date/time (oldest first) |
g |
Group directories first |
- |
Reverse order (prefix any letter with a minus) |
Example: list files largest to smallest:
dir /o-s
Pausing Output for Long Lists
When a directory contains hundreds of entries, the screen can scroll too fast to read. The /p switch pauses after each screenful:
dir /p
Press any key to continue to the next page.
Using Wildcards and Filters
Wildcards let you match patterns instead of typing exact names.
*matches any sequence of characters.?matches a single character.
Examples
dir *.txt :: all files ending with .txt
dir report?.docx :: report1.docx, report2.docx, but not report10.docx
dir *2023*.pdf :: any PDF with “2023” somewhere in the name
You can combine wildcards with attribute switches:
dir /a:h *.log :: hidden log files only
Advanced Options
Showing File Ownership
The /q switch displays the file owner alongside each name:
dir /q
Displaying Alternate Data Streams
On NTFS volumes, files can have hidden streams. Use /r to list them:
dir /r
Controlling Time Format
Switches /t, /tc, /ta, and /tw let you choose which timestamp to show (creation, last access, last write) and optionally change the format:
dir /t:c :: show creation time
dir /t:w :: show last write time (default)
Four‑Digit Year Display
Older versions of Windows showed two‑digit years. Force a four‑digit year with /4:
dir /4
Showing File Compression and Encryption
The /c switch displays the compression ratio; /e shows encrypted files in color (if the console supports it):
dir /c
dir /e
Combining dir with Other Commands
The true power of the Command Prompt appears when you pipe (|) or redirect (>) the output of dir into other utilities.
Filtering with findstr
To show only files that contain a certain word in their name:
dir /b | findstr /i "invoice"
The /i flag makes the search case‑insensitive And that's really what it comes down to. Worth knowing..
Saving a List to a Text File
Redirect the output to a file for later reference or processing:
dir /b > filelist.txt
You can append instead of overwrite by using >>:
dir /b >> filelist.txt
Looping Through Files in a Batch Script
A common pattern is to process each file returned by dir:
for /f "delims=" %F in ('dir /b *.jpg') do (
echo Processing %F
:: place your command here, e.g., convert %F %F.png
)
In a batch file, double the percent signs (%%F).