How to Sort MS-DOS 6.22 DIR by Date and Time
The DIR command in MS-DOS 6.22 provides built-in
functionality to organize directory listings chronologically rather than
displaying them in the order they exist on the disk. By appending the
sort switch /O combined with the date parameter
D, users can display files and subdirectories ordered from
oldest to newest or reverse the order to view the most recently modified
files first.
The Basic Chronological Sort Syntax
To sort directory contents in chronological order (oldest files
first), use the /O (Order) switch followed by the
D (Date) parameter:
DIR /O:D(Note: The colon is optional; DIR /OD functions
identically.)
When this command runs, MS-DOS evaluates the last-modified timestamp of each file and subdirectory, presenting the oldest entries at the top of the list and the newest entries at the bottom.
Sorting in Reverse Chronological Order
To display files in reverse chronological order (newest files first),
add a minus sign (-) directly before the D
parameter:
DIR /O:-DThis syntax instructs the operating system to invert the date sort, placing the most recently created or updated files at the top of the output.
Combining with Display Modifiers
Because directory listings can be lengthy, the chronological sort switch is frequently paired with display switches:
- Paginated Output (
/P): To pause scrolling after each screenful of data, append/P:DIR /O:D /P - Include Subdirectories (
/S): To view all files across the current directory and all subdirectories sorted chronologically within their respective folders:DIR /O:D /S - Bare Format (
/B): To display only file and directory names in chronological sequence without size, date, or header details:DIR /O:D /B
Setting a Permanent Default Sort Order
If you prefer MS-DOS 6.22 to always sort directory listings
chronologically without having to type the switch every time, you can
configure the DIRCMD environmental variable. Adding the
following line to your AUTOEXEC.BAT file applies the date
sort as the system default:
SET DIRCMD=/O:DTo override this default temporarily during a DOS session, you can
run DIR /O with a different parameter or use
DIR /-O to view files in unsorted disk order.