ShareYourGroupShareYourGroupCommands

Windows commands

dir: list the files in a folder

dir shows what is in a folder. It is the first command most people learn, because you cannot work with files until you can see them. It only looks. It changes nothing, so it is completely safe to try.

The basic listing

Windows Command Prompt
C:\Users\asha\demo>dir
 Volume in drive C is Windows
 Volume Serial Number is 1A2B-3C4D

 Directory of C:\Users\asha\demo

01/11/2026  15:00    <DIR>          .
12/11/2026  08:44    <DIR>          ..
01/11/2026  15:00               222 log.txt
01/11/2026  15:00                53 marks.csv
01/11/2026  15:00                51 notes.txt
01/11/2026  15:00    <DIR>          old
01/11/2026  15:00    <DIR>          photos
01/11/2026  15:00                94 report.txt
               4 File(s)            420 bytes
               4 Dir(s)  159,243,091,968 bytes free

Reading the output from the left: the date and time each item was last changed, then either <DIR> for a folder or the size in bytes for a file, then the name. The two entries . and .. stand for this folder and the folder above it. The last lines count the files and their total size, and show the free space on the disk.

Just the names

The /b switch, for bare, prints names only. It is the form to use when you want to copy the list somewhere.

Windows Command Prompt
C:\Users\asha\demo>dir /b
log.txt
marks.csv
notes.txt
old
photos
report.txt

Another folder

Give a folder name to list that folder without going into it.

Windows Command Prompt
C:\Users\asha\demo>dir photos
 Volume in drive C is Windows
 Volume Serial Number is 1A2B-3C4D

 Directory of C:\Users\asha\demo\photos

01/11/2026  15:00    <DIR>          .
01/11/2026  15:00    <DIR>          ..
01/11/2026  15:00                39 beach.jpg
01/11/2026  15:00                39 hills.jpg
               2 File(s)             78 bytes
               2 Dir(s)  159,243,091,968 bytes free

Wildcards

A star stands for any run of characters, and a question mark for exactly one. *.txt means every name ending in .txt.

Windows Command Prompt
C:\Users\asha\demo>dir *.txt
 Volume in drive C is Windows
 Volume Serial Number is 1A2B-3C4D

 Directory of C:\Users\asha\demo

01/11/2026  15:00               222 log.txt
01/11/2026  15:00                51 notes.txt
01/11/2026  15:00                94 report.txt
               3 File(s)            367 bytes
               0 Dir(s)  159,243,091,968 bytes free
C:\Users\asha\demo>dir /b *.csv
marks.csv

Including the folders inside

/s lists this folder and every folder inside it. With /b it gives the full path of each file, one per line.

Windows Command Prompt
C:\Users\asha\demo>dir /s /b
C:\Users\asha\demo\log.txt
C:\Users\asha\demo\marks.csv
C:\Users\asha\demo\notes.txt
C:\Users\asha\demo\old
C:\Users\asha\demo\photos
C:\Users\asha\demo\report.txt
C:\Users\asha\demo\old\draft.txt
C:\Users\asha\demo\photos\beach.jpg
C:\Users\asha\demo\photos\hills.jpg

On a large folder this can run to thousands of lines. Press Ctrl + C to stop it.

Sorting

/o sets the order. Follow it with a letter: n for name, s for size, d for date, e for the ending of the file name. A minus sign reverses the order.

Windows Command Prompt
C:\Users\asha\demo>dir /o-s
 Volume in drive C is Windows
 Volume Serial Number is 1A2B-3C4D

 Directory of C:\Users\asha\demo

01/11/2026  15:00               222 log.txt
01/11/2026  15:00                94 report.txt
01/11/2026  15:00                53 marks.csv
01/11/2026  15:00                51 notes.txt
01/11/2026  15:00    <DIR>          old
01/11/2026  15:00    <DIR>          photos
12/11/2026  08:44    <DIR>          ..
01/11/2026  15:00    <DIR>          .
               4 File(s)            420 bytes
               4 Dir(s)  159,243,091,968 bytes free

That lists the largest files first. dir /od puts the oldest first and the newest last, which is handy for finding what changed most recently.

Only folders, or only files

/a filters by attribute. /ad shows folders only, /a-d files only, and /ah hidden items, which a plain dir leaves out.

Windows Command Prompt
C:\Users\asha\demo>dir /ad /b
old
photos

The switches, in one table

SwitchEffect
/bbare: names only
/sinclude all subfolders
/ashow hidden and system items too
/adfolders only
/a-dfiles only
/on, /os, /odsort by name, size, date
/o-dnewest first
/ppause after each screenful
/wwide: names in columns
/qshow who owns each file

Switches can be combined: dir /s /b /a-d *.jpg lists every JPG file in this folder and below, with full paths.

Saving the list to a file

The > sign sends the output of any command into a file instead of the screen. This makes a text file listing the folder's contents.

Windows Command Prompt
C:\Users\asha\demo>dir /b > list.txt
C:\Users\asha\demo>type list.txt
list.txt
log.txt
marks.csv
notes.txt
old
photos
report.txt

Notice that list.txt appears in its own list, because the file was created before dir looked. To add to the end of an existing file without wiping it, use >>.

Common questions

The list scrolls past too fast. Add /p, or pipe it through more: dir | more.

A file I know is there does not show. It may be hidden. Use dir /a.

Names with spaces. Put the name in double quotation marks: dir "My Documents".

What is the short form? There is none on Windows, though in PowerShell ls and dir both work. On Linux and the Mac the command is ls.

Getting help

Every Windows command explains itself when followed by /?. dir /? prints the full list of switches.

Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.

This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.