yjfuk yjfuk - 1 month ago 7
Bash Question

How could the UNIX sort command sort a very large file?

The UNIX

sort
command can sort a very large file like this:

sort large_file


How is the sort algorithm implemented?

How come it does not cause excessive consumption of memory?

Answer

The Algorithmic details of UNIX Sort command says Unix Sort uses an External R-Way merge sorting algorithm. The link goes into more details, but in essence it divides the input up into smaller portions (that fit into memory) and then merges each portion together at the end.

Comments