dirDIR /A:H /O:S: List Hidden Files Sorted by Size
Learn how to use DIR /A:H /O:S to list hidden files and sort them by size in Windows CMD, with examples and troubleshooting tips.
The dir /a:h /o:s command lists hidden files in a directory and sorts them by size, smallest to largest. It is a fast way to identify hidden files and understand their storage impact without enabling hidden file views in Explorer.
Whether you are troubleshooting hidden malware artifacts, auditing storage usage, or cleaning up system folders, dir /a:h /o:s provides a clear, sorted list of hidden files for analysis and action.
This guide covers syntax, examples, use cases, troubleshooting, related commands, FAQs, and a quick reference card. By the end, you will confidently list and sort hidden files from the command line.
What Does DIR /A:H /O:S Do?
DIR /A:H filters output to files with the Hidden attribute. DIR /O:S sorts by size in ascending order. Combined, the command shows hidden files sorted by size, helping you spot large hidden files quickly or verify that hidden system files are expected.
Syntax
DIR /A:H /O:S [path]
Parameters and Options
| Parameter | Description | Example |
|---|---|---|
/A:H | Show hidden files only | DIR /A:H |
/O:S | Sort by size (smallest first) | DIR /O:S |
/O:-S | Sort by size (largest first) | DIR /O:-S |
/S | Recursive listing | DIR /A:H /O:-S /S |
Examples (HowTo)
1. List hidden files sorted by size
Scenario: You want to see hidden files in the current folder and their sizes.
DIR /A:H /O:S
Explanation: Outputs hidden files only, sorted smallest to largest.
2. Sort hidden files by size (largest first)
Scenario: You want to find the largest hidden files quickly.
DIR /A:H /O:-S
Explanation: The largest hidden files appear at the top of the listing.
3. Target a specific path
Scenario: You want hidden files in a specific directory.
DIR /A:H /O:S C:\Data
Explanation: Filters and sorts hidden files in C:\Data.
4. Recursive hidden file scan
Scenario: You suspect hidden files in subfolders.
DIR /A:H /O:-S /S C:\Data
Explanation: Lists all hidden files across the directory tree, sorted by size.
5. Export hidden file list
Scenario: You need a report for auditing or cleanup.
DIR /A:H /O:-S /S C:\Data > C:\Reports\hidden-files.txt
Explanation: Saves the sorted hidden file list to a file.
6. Combine with bare format for scripts
Scenario: You need a name-only list for automation.
DIR /A:H /O:-S /S /B C:\Data
Explanation: Outputs paths only, sorted by size order from the full listing.
Common Use Cases
-
Hidden file audits – Identify hidden files in sensitive directories.
-
Malware cleanup – Spot suspicious hidden files by size.
-
Storage analysis – Find large hidden files consuming disk space.
-
System verification – Confirm hidden system files exist where expected.
-
Compliance checks – Document hidden file usage in restricted areas.
-
Backup review – Verify hidden files are included in backups.
-
Incident response – Collect evidence about hidden artifacts.
-
User cleanup – Identify hidden files left by applications.
-
Policy enforcement – Validate that users are not hiding large files.
-
Forensic baselining – Compare hidden file lists across systems.
Tips and Best Practices
-
Use /O:-S for quick size triage – Largest files first save time.
-
Combine with /S carefully – Recursive scans can be large and slow.
-
Export results – Save reports for audits or cleanup tasks.
-
Use /B for scripts – Bare output is easier to parse.
-
Confirm current directory – Avoid running on unintended paths.
-
Check with attrib – Use
attribto confirm Hidden attribute state. -
Do not delete blindly – Hidden does not always mean malicious.
-
Use admin rights when needed – Some hidden files require elevation to view.
-
Pair with malware scans – Use security tools when suspicious files appear.
-
Document before changes – Always capture a before-and-after list.
Troubleshooting Common Issues
Hidden files not shown
Problem: The list is empty.
Cause: No hidden files in the target directory or insufficient permissions.
Solution: Run with admin rights or test another directory.
Prevention: Verify with DIR /A to see all attributes.
Output is too large
Problem: Recursive output is overwhelming.
Cause: Large directory tree with many hidden files.
Solution: Narrow the path or remove /S.
Prevention: Start with a specific folder rather than the drive root.
Sorting seems incorrect
Problem: Files are not ordered by size.
Cause: Missing /O:S or mixing output with other parameters.
Solution: Use exactly DIR /A:H /O:S or DIR /A:H /O:-S.
Prevention: Validate with a small test folder first.
Access denied
Problem: Errors appear for protected folders.
Cause: Insufficient permissions.
Solution: Run CMD as Administrator or skip restricted paths.
Prevention: Limit scans to locations you control.
Related Commands
attrib
View or change hidden attributes directly.
dir /a
List files by attributes without filtering to hidden only.
dir /o:s
Sort by size for all files, not just hidden ones.
dir /b
Bare output format for scripting.
findstr
Filter directory output by name patterns.
Frequently Asked Questions
What does /A:H do?
It filters output to hidden files only.
What does /O:S do?
It sorts files by size, smallest first.
How do I sort largest first?
Use /O:-S to reverse the order.
Can I include subdirectories?
Yes, add /S for recursive scanning.
Why do I see access denied messages?
Some protected folders require admin rights.
Is this command safe?
Yes, it is read-only and does not modify files.
Can I hide files with dir?
No, use attrib +h to set hidden attributes.
What is the best way to export the list?
Redirect output to a file using >.
Quick Reference Card
| Command | Purpose | Example |
|---|---|---|
DIR /A:H /O:S | Hidden files sorted by size | DIR /A:H /O:S |
DIR /A:H /O:-S | Hidden files largest first | DIR /A:H /O:-S |
DIR /A:H /O:-S /S | Recursive hidden file scan | DIR /A:H /O:-S /S C:\Data |
DIR /A:H /O:-S /S > file.txt | Export list | DIR /A:H /O:-S /S C:\Data > hidden.txt |
CTA: Practice and Explore
Practice directory commands in the Windows Command Simulator and explore the Commands Reference for related file tools like dir, attrib, and findstr. Learn more about this project on the About page.
Summary
DIR /A:H /O:S is a fast, read-only way to list hidden files and sort them by size. Use it to identify hidden files, troubleshoot suspicious artifacts, or audit storage usage without changing Explorer settings.
For large investigations, add /S for recursion and /O:-S for largest-first sorting. Always review results before taking action and use attrib if you need to change hidden attributes.