How to ls in windows
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- The `dir` command is Windows' equivalent to the `ls` command in Unix-like systems.
- It can be used in both Command Prompt (cmd.exe) and PowerShell.
- Basic usage is `dir` to list contents of the current directory.
- Common options include `/w` for wide format and `/p` for pausing after each screen.
- You can use `dir /s` to list files in subdirectories.
Overview
For users accustomed to Linux, macOS, or other Unix-based operating systems, the `ls` command is a fundamental tool for navigating and understanding file structures. It's used to list directory contents. When transitioning to Windows, many users wonder about the equivalent command. Fortunately, Windows provides a built-in command-line utility that serves the same purpose: the `dir` command.
Both the traditional Command Prompt (cmd.exe) and the more modern Windows PowerShell support the `dir` command. While the underlying shells are different, the core functionality of `dir` remains consistent, making it easy for new users to adapt. This article will guide you through the basics of using the `dir` command in Windows, covering its most common uses and useful options.
What is the `dir` Command?
The `dir` command, short for "directory," is a command-line utility in Windows that displays a list of files and subdirectories within a specified directory. When you open Command Prompt or PowerShell and type `dir` without any arguments, it will show you the contents of the current directory you are in. This is analogous to typing `ls` in a Unix terminal.
How to Use the `dir` Command
Opening Command Prompt or PowerShell
Before you can use the `dir` command, you need to open either Command Prompt or PowerShell. You can do this by:
- Pressing the Windows key + R to open the Run dialog.
- Typing `cmd` (for Command Prompt) or `powershell` (for PowerShell) and pressing Enter.
- Alternatively, you can search for "Command Prompt" or "PowerShell" in the Windows search bar and click to open it.
Basic Usage
Once the terminal window is open, navigate to the directory you want to inspect (if you're not already there) using the `cd` (change directory) command. Then, simply type:
dir
Press Enter. This will display a list of files and folders in the current directory, along with their last modification date, time, and type (either '
Listing Contents of Another Directory
You can also specify a path to list the contents of a different directory without navigating to it first. For example:
dir C:\Users\YourUsername\Documents
Replace `C:\Users\YourUsername\Documents` with the actual path you want to examine.
Useful `dir` Command Options
The `dir` command is highly versatile and offers numerous options (often called switches) that can modify its output. These options are typically preceded by a forward slash (`/`). Here are some of the most commonly used ones:
Wide Format (`/w`)
To display the directory listing in a wider format with file and directory names listed horizontally, separated by commas, use the `/w` switch:
dir /w
This is useful when you have many files and want to see more names on a single line.
Pause After Each Screen (`/p`)
If a directory contains a large number of files, the output might scroll past too quickly. The `/p` switch pauses the display after each screenful of information, prompting you to press any key to continue:
dir /p
List Subdirectories (`/s`)
To display files in the current directory and all its subdirectories, use the `/s` switch:
dir /s
This is very powerful for finding files across a directory tree.
Show Hidden Files (`/a`)
By default, `dir` might not show hidden files. To display all files, including hidden and system files, use the `/a` switch:
dir /a
You can also specify attributes, like `dir /ah` to show only hidden files.
Sort Order (`/o`)
You can sort the directory listing by various criteria using the `/o` switch. Common sorting options include:
- `/o:n` - Sort by name (alphabetically)
- `/o:e` - Sort by extension (alphabetically)
- `/o:s` - Sort by size (smallest first)
- `/o:d` - Sort by date/time (oldest first)
You can reverse the sort order by prefixing the sort key with a hyphen (`-`). For example, to sort by size in descending order (largest first):
dir /o:-s
Display File Sizes in KB (`/k`)
To display file sizes in kilobytes, use the `/k` switch.
dir /k
Combine Options
You can combine multiple options together. For example, to list all files and subdirectories in wide format, pausing after each screen:
dir /w /p
Or to list all files, including hidden ones, sorted by date (oldest first):
dir /a /o:d
`ls` vs. `dir` - Key Differences
While `dir` is the functional equivalent of `ls`, there are some nuances:
- Syntax: `ls` uses hyphens (`-`) for options (e.g., `ls -l`), whereas `dir` uses forward slashes (`/`) (e.g., `dir /w`).
- Output Format: The default output of `ls -l` is typically more detailed than the default `dir` output, showing permissions, owner, group, etc., which are not standard in Windows file systems in the same way.
- Aliases: In PowerShell, you can create an alias for `ls` that points to `dir` or other commands to make the transition smoother. Type `Set-Alias ls dir` in PowerShell to set this alias for your current session. To make it permanent, you'd need to add it to your PowerShell profile.
Conclusion
The `dir` command is your primary tool for listing directory contents in Windows Command Prompt and PowerShell. By mastering its basic usage and exploring its various options, you can efficiently navigate and manage your files and directories, much like you would with `ls` on other operating systems. Remember to use the forward slash (`/`) for options and consult the command's help by typing `dir /?` for a comprehensive list of all available switches.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- dir Command - Windows Commands | Microsoft Learnfair-use
- DIR - List directory contents - Windows CMD - SS64fair-use
- Ls - WikipediaCC-BY-SA-4.0
Missing an answer?
Suggest a question and we'll generate an answer for it.