sort
ShellFundamentals In simulator In real LinuxSort lines of text
Name: sort
You can practise it right away in the simulator, and use it in real Linux mode too.
Description
sort sorts all input lines. By default it compares characters according to the locale; -n compares numbers, -h human sizes like 2K or 1G, -k a chosen field, and -t sets the field separator.
sort has to read all input before printing anything. It pairs with uniq, which only handles adjacent duplicates.
Syntax
sort [OPTION]... [FILE]...Common options
| -n / --numeric-sort | Compare as numbers |
| -h / --human-numeric-sort | Compare human-readable sizes like 2K, 1G |
| -V / --version-sort | Sort version numbers (1.9 before 1.10) |
| -M / --month-sort | Sort by month name (Jan < Feb < …) |
| -r / --reverse | Reverse the order |
| -k / --key KEYDEF | Sort by field N, e.g. -k2 |
| -t / --field-separator SEP | Field separator, e.g. -t, |
| -u / --unique | Output only unique lines |
| -f / --ignore-case | Ignore case |
| -s / --stable | Stable: lines that compare equal keep their order |
| -R / --random-sort | Shuffle (equal lines stay together) |
| -o / --output FILE | Write the result to FILE (it may be the input: sort -o f f is safe) |
| -c / --check | Only check whether it is sorted |