What Does the Windows DIR Command Do? 5 Flags Worth Memorizing
The Windows DIR command lists files and folders in Command Prompt. Used well, it is faster than clicking through File Explorer — especially when you need hidden files, recursive searches, or script-friendly file lists. This guide explains what dir does, then covers five switches worth memorizing. For the official switch list, see Microsoft Learn’s DIR command reference . What does DIR do? Open…
The Windows DIR command provides a list of files and folders in the Command Prompt. It is typically faster than navigating through File Explorer, particularly for tasks like finding hidden files, performing recursive searches, or generating file lists suitable for scripting. This article explains what DIR does and highlights five flags that are worth memorizing for efficient use. For a more comprehensive list of switches, refer to Microsoft Learn's DIR command reference.
When you open Command Prompt and run the command: dir, it displays every file and folder in the current directory, including the last write time, size for files, and folder name for directories. This inventory operation is the core function of DIR. However, the command can be customized with flags to change the way the inventory is displayed and filtered.
DIR is often compared to File Explorer in terms of functionality. While File Explorer offers a graphical interface that may hide certain hidden or system files by default, DIR provides a command-line alternative that can reveal hidden/system files, search deeply within folder structures, and produce output in various formats that are particularly useful for script-driven workflows.
Here are five DIR flags that are particularly useful:
1. /w — Wide view: This flag presents the file list in columns, offering a quick visual scan of a crowded folder without the need to adjust column headers or delve into metadata.
2. /a — Include attributes: By adding /a, DIR includes additional attributes, such as hidden items that are typically omitted from the listing when /a is not specified. Narrowing down the list with /a :h will show only hidden files, which can be helpful when searching for "missing" files that are merely marked as hidden.
3. /s — Search subfolders: Using /s allows DIR to list matches not just in the current folder but also in every subfolder. This is particularly useful when you know the file name pattern but not the exact path. Pairing it with a pattern, such as *.log, will display all matching files across the entire directory tree.
4. /o: — Sort the listing: DIR enables sorting of the listing with the /o: flag. Common sort keys include /o:n for sorting by name, /o:d for sorting by date (oldest first), /o:-d for sorting by date (newest first), and /o:s for sorting by size.
5. /b — Bare format (names only): When /b is used, DIR outputs only the names of files and folders, one per line, without any headers or additional metadata. This format is ideal for scripting, where you may need a simple list of names to process.
The flags can be combined to create efficient workflows. For example, to quickly scan a directory for the newest .dll files, the command would be: dir /b /s /o:-d * .dll. This command sorts the files by the newest date and lists only the names of the .dll files found in the current directory and all subdirectories.
Practicing DIR commands regularly will help cement these flags as muscle memory. Newcomers to Command Prompt are encouraged to run dir /? to view the complete list of switches, then focus on mastering the five flags discussed in this article. For those looking for interactive learning, CMD Master offers a free online platform for practicing CMD, PowerShell, and Bash in a live browser terminal, providing instant feedback without the need for installation or a virtual machine.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.