The sort command is used filter input and then display the results on a computer monitor or writes them to a file.
Availability
Sort is an external command that is available for the following Microsoft operating systems as sort.exe.
Availability
Sort syntax
Sort examples
All Versions of MS-DOS
Windows 95
Windows 98
Windows ME
Windows NT
Windows 2000
Windows XP
Windows Vista
Windows 7
Windows 8
Windows 10
Windows 11
Sort syntax
Windows 2000, XP, and later syntax
SORT [/R] [/+n] [/M kilobytes] [/L locale] [/REC recordbytes] [[drive1:][path1]filename1] [/T [drive2:][path2]] [/O [drive3:][path3]filename3]
MS-DOS, Windows 95, 98, ME, and NT syntax
Sorts input and writes results to the screen, a file, or another device.
- Windows 2000, XP, and later syntax.
- MS-DOS, Windows 95, 98, ME, and NT syntax.
The best performance is usually achieved by not specifying a memory size. By default, sort is done in one pass (no temporary file) if the sort fits in the default maximum memory size. Otherwise, the sort is done in two passes (with the partially sorted data being stored in a temporary file) such that the amounts of memory used for both the sort and merge passes are equal. The default maximum memory size is 90% of available main memory if both the input and output are files, and 45% of main memory otherwise.
SORT [/R] [/+n] [[drive1:][path1]filename1] [> [drive2:][path2]filename2] [command |] SORT [/R] [/+n] [> [drive2:][path2]filename2]
Sort examples
sort test.txt
This command would display the sorted results of the text in test.txt.
sort test.txt /o output.txt
This next command takes the sorted results and stores them in the output.txt file.
If you want to sort the listing of the files, you can use the dir command with one of the sorting switches. For example, “dir /on” sorts the files listed in alphabetical order. See the dir command page for further examples and options.
Related information
- See our sort definition for further information and related links on this term.