Share via

List all the options and switches for the microsoft powershell DIR command

Rich Wilk 0 Reputation points
2026-03-19T10:04:12.0133333+00:00

Make the list of the DIR command's options, switches and other useful DIR or ls options

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Jason Nguyen Tran 13,975 Reputation points Independent Advisor
    2026-03-25T03:21:19.8133333+00:00

    Hi Rich Wilk,

    I’m following up to check whether the issue has been resolved. Feel free to reply if you need further information. If the information provided was helpful, please click "Accept Answer" to help others in the community. Thank you!

    0 comments No comments

  2. Jason Nguyen Tran 13,975 Reputation points Independent Advisor
    2026-03-19T10:59:07.2833333+00:00

    Hi Rich Wilk,

    Below is a complete list of useful switches, parameters, and equivalents for both CMD and PowerShell.

    1. Classic CMD dir Options

    These are the traditional switches available in Command Prompt:

    Switch Description

    • /p Pauses after each screen of output
    • /q Displays file ownership
    • /w Wide list format (multiple names per line)
    • /d Wide list format, sorted by column
    • /a Displays files with specified attributes (e.g., /a:h for hidden)
    • /o Sorts output (e.g., /o:n by name, /o:-n descending)
    • /s Recursively lists files in all subdirectories
    • /b Bare format (just names, no metadata)
    • /l Uses lowercase
    • /n New long list format (names on the right)
    • /x Shows short (8.3) file names
    • /c Displays thousand separators in file sizes
    • /t Controls which time field to display (creation, last access, last write)

    2. PowerShell DIR (Alias for Get-ChildItem)

    PowerShell expands functionality with parameters:

    Parameter Description

    • -Path Specifies directory or file path
    • -Filter Filters results using a string (wildcards supported)
    • -Include Includes only specified file types
    • -Exclude Excludes specified file types
    • -Recurse Recursively lists all subdirectories
    • -Force Shows hidden and system files
    • -Name Displays only file/directory names (like /b)
    • -Attributes Filters by attributes (e.g., Hidden, Directory)
    • -Directory Lists only directories
    • -File Lists only files
    • -Depth Limits recursion depth
    • -ErrorAction Controls error handling (e.g., SilentlyContinue)

    3. Useful Equivalents

    • CMD dir /s /b > PowerShell:
        Get-ChildItem -Recurse -Name
      
    • CMD dir /a:h (hidden files) > PowerShell:
        Get-ChildItem -Force
      
    • CMD dir /o:n (sort by name) > PowerShell:
        Get-ChildItem | Sort-Object Name
      

    I hope the response provided some helpful insight. If it clarified the issue for you, please consider marking it as Accept Answer so others with the same issue can find the solution.

    Jason.

    0 comments No comments

  3. Q&A Assist
    2026-03-19T10:04:42.38+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    For classic cmd.exe the dir command options are:

    • [<drive>:][<path>] – Drive and directory to list.
    • [<filename>] – File or file pattern to list (supports wildcards * and ?).

    Switches:

    • /p – Pause after each screen of output.
    • /q – Show file ownership information.
    • /w – Wide format (multiple names per line).
    • /d – Wide format, sorted by column.
    • /a[[:]attributes] – Show only items with specific attributes. Attributes:
      • d – Directories
      • h – Hidden files
      • s – System files
      • l – Reparse points
      • r – Read-only files
      • a – Ready for archiving
      • i – Not content indexed files
      • - prefix means “not”, e.g. /a:-d = files only, no directories.
    • /o[[:]sortorder] – Sort order. Values:
      • n – Name (alphabetical)
      • e – Extension (alphabetical)
      • g – Group directories first
      • s – Size, smallest first
      • d – Date/time, oldest first
      • - prefix reverses order, e.g. /o:-n.
    • /t[[:]timefield] – Which timestamp to display/sort by:
      • c – Creation time
      • a – Last accessed
      • w – Last written
    • /s – Recurse into all subdirectories.
    • /b – Bare format (names only, no header/summary). Overrides /w.
    • /l – Use lowercase, unsorted.
    • /n – Long list format with names on the far right.
    • /x – Show 8.3 short names in addition to long names.
    • /c – Show thousand separators in sizes (default). Use /-c to hide.
    • /4 – Four‑digit years.
    • /r – Show alternate data streams.
    • /? – Help for dir.

    Useful dir usage patterns (cmd):

    • List all files and folders in current directory:
      • dir
    • List all .txt files on C: recursively, wide, sorted, with paging:
      • dir c:\*.txt /w /o /s /p
    • List only files (no directories), bare format, suitable for piping/redirecting:
      • dir /a:-d /b
    • Redirect listing to printer or file:
      • dir > prn
      • dir > \records\dir.doc

    PowerShell dir / ls alias:

    In PowerShell, dir and ls are aliases for Get-ChildItem.

    Key Get-ChildItem options relevant to dir/ls behavior:

    • -Path – Target path (default is current location).
    • -Recurse – Recurse into child containers.
    • -Depth <n> – Limit recursion depth.
    • -Directory (alias -ad) – Return directories only.

    Notes:

    • Aliases:
      • All platforms: dir, gci
      • Windows: ls
    • When using Get-ChildItem -Recurse with -Path, the last path component is treated specially (can trigger recursive search for that component). For predictable recursion:
      • Prefer -LiteralPath for the base directory.
      • Use -Filter or -Include for patterns.

    Examples (PowerShell):

    • List items in current directory:
      • dir or ls or Get-ChildItem
    • Recursive listing of all .txt files under C:\Data:
      • Get-ChildItem -LiteralPath 'C:\Data' -Recurse -Filter '*.txt'
    • Directories only:
      • Get-ChildItem -Directory

    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.