Search notes:

cmd.exe - dir

dir lists files and directories in a given directory or the current directory:

Options

dir accepts the following options:
/A, /Ax, /A-x /A: Show all files, /Ax: include files with attribute x in listing, /A-x: exclude files with attribute x (See below for x)
/B Use bare format, that is: only show file and directory name, without their sizes and/or creation date (compare with the parameter -name of the PowerShell cmdLet get-childItem.
/C, /-C Show, don't show thousand separator in file sizes (/C is default)
/D, /W Wide (multi-column) format. /D sorts file first in left most column, /W sorts from top to bottom, then from left to right
/L Print file names in lowercase
/-N Show filenames to the left (/N is default)
/Ox Sort files according to criterion x
/P Paginate output
/Q Print file owner
/R Include alternate data streams of file
/S Include subdirectories
/T:x Specify displayed time field (x) for displaying or sorting (c: creation, a: last acess, w: last written)
/X Show short file names
/4 Use 4-digit year (is this not the default anyway?)

Sort files and directories

dir /ox sorts the listed files. x specifies the sorting criteria:
n alphabetically
e filename extension
s size
d modification time and date
g show group directories first
If the sorting criteria letter is prepended with a dash, the sorting order is reversed. The following command shows the newest files/directories first:
C:\Users\Rene> dir /o-d

Include / exclude files with specific attributes

/Ax includes, /A-x excludes files with a given attribute x. /A shows all files, no matter what their attributes.
The possible values for x are:
d Directories
h Hidden files
s System files
l Reparse points
r Read-only files
a Files ready for archiving
i Not content indexed files
o Offline files
Attributes can be set or removed with attrib.exe.

Environment variable DIRCMD

The environment variable DIRCMD controls the default options given to dir.
It might be set, for example, to /ogn /a to always show the directories first and sort by file/directory name and to show all (including hidden) files.

Recursively searching for files that match a wildcard

In order to search for files that match a given wildcard in and below the current directory, the /s option must be used:
C:\Users\Rene> dir /s *quarter*.xls*
However, unfortunately, I find the output quite unreadable because it is cluttered with directory names and file attributes that I am (usually) not interested in. The option /b (bare format) only prints (absolute) filenames, which makes the reading of the result much easier:
C:\Users\Rene> dir /s /b *quarter*.xls*
In PowerShell, the effect of dir /s /b can be achieved by using a variant of a pipeline like so:
PS C:\Users\Rene> get-childItem -recurse -filter *quarter*.xls* | select-object fullname

Display owner of files and directories

The owner of files and directories is shown with /q:
dir /q %SystemRoot%

Show junctions

dir /al shows junctions (aka reparse points).

See also

cmd.exe: Built-in commands

Index