Problem Statement
What does the sort -u command do?
Explanation
Sort -u sorts lines in ascending order and removes duplicate lines, combining the functionality of sort and uniq. It's more efficient than piping sort | uniq because it removes duplicates during sorting rather than as a separate step. This is useful for generating unique sorted lists from data with potential duplicates.
The sort command has many useful options: -n for numerical sort (treating content as numbers), -r for reverse order, -k for sorting by specific field, -t for specifying field delimiter, and -h for human-readable numbers (1K, 1M, 1G). Example: sort -t':' -k3 -n /etc/passwd sorts users by UID.
Common usage includes sorting command output like ls -l | sort -k5 -n to sort files by size, or du -h | sort -h to sort disk usage. Use sort for organizing data, finding top/bottom items, or preparing data for uniq command. Understanding sort options enables efficient data manipulation and analysis from command line.
