Windows CMDInteractive Lab
File Managementdir

List Hidden Files and Sort by Size in CMD

Need to list hidden files and sort by file size in Windows CMD? Use the correct DIR command syntax with clear examples and troubleshooting steps.

Rojan Acharya··Updated Apr 17, 2026
Share

To list hidden files in a directory and sort them by file size in Windows Command Prompt, use:

DIR /A:H /O:S

/A:H filters hidden entries and /O:S sorts by size from smallest to largest.

Why This Command Is Correct

The command combines two distinct controls:

  • Attribute filter: hidden files only.
  • Sort order: size-based ordering.

It directly answers common multiple-choice variants where other options use the wrong attribute or sort code.

Syntax

DIR [path] /A:H /O:S

Examples

DIR /A:H /O:S
DIR C:\Users\Public /A:H /O:S
DIR /A:H /O:-S
DIR /A:H /O:S /B
DIR /A:H /O:S /S

Common Use Cases

  • Hidden file audits.
  • Basic malware triage.
  • Checking hidden app cache growth.
  • Preparing file cleanup plans.

Tips and Best Practices

  • Add /A:-D if you need files only.
  • Use /O:-S for largest-first view.
  • Use /B before piping output.

Troubleshooting

No results returned

Directory may not contain hidden entries.

Directories included unexpectedly

Use DIR /A:H /A:-D /O:S pattern in staged checks.

Sort direction wrong

Use /O:-S for descending.

Access denied

Run elevated CMD in restricted paths.

Related Commands

Frequently Asked Questions

What is the exact command?

DIR /A:H /O:S.

What does /A:H do?

Shows hidden entries only.

What does /O:S do?

Sorts by size ascending.

How do I show largest hidden files first?

Use /O:-S.

Can I search recursively?

Yes, add /S.

Can I output only names?

Yes, add /B.

Will this include hidden folders too?

It can; add file-only filtering if needed.

Is this valid on Windows 11?

Yes.

Quick Reference Card

NeedCommand
Hidden sorted by sizeDIR /A:H /O:S
Hidden largest firstDIR /A:H /O:-S
Hidden recursiveDIR /A:H /O:S /S
Hidden bare outputDIR /A:H /O:S /B
Hidden in specific pathDIR C:\Path /A:H /O:S

CTA

Try this command in the Windows Command Simulator and review more listing patterns in Commands Reference.

Summary

The right command for hidden files sorted by size is DIR /A:H /O:S. Add /S, /B, or - modifiers depending on output scope and sort direction.