Low Orbit Flux Logo 2 F

Linux Command - sort

The Linux sort command is used to sort lines of text within a file. You can sort the lines of actual files or the output of another piped command.

Sort lines in file in alphabetical order



sort file1.txt

Sort and display unique lines:



sort -u file1.txt

Sort in reverse:



sort -r file1.txt

Sort by numerical values:



sort -n file1.txt

Sort output of a piped command:



ps -ef | sort 

Sort output numerically and in reverse to find largest files at the top:



du -sk /var/log/* | sort -nr

Similar but with human readable values ( ex. 8k, 10M, 3G ):



du -sh /var/log/* | sort -h

Sort by sepecific column using a key:



sort -k 5,5 file1.txt

Case insensitive sort:



sort -f file1.txt

Sort by specific column and delimit columns with tabs:



sort -t$'\t' -k 5,5 file1.txt

NOTE - A huge number of additional options exist.