aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cli/sort.md
blob: e74b4903869e5ed3c8b9eaabe6a2adce7e4d8658 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# sort(1)

```
sort [opts] [file]
  opts:
    -r      reverse output
    -b      ignore leading blanks

    -n      sort by numeric
    -h      sort by human numeric
    -V      sort by version

    -k<N>  sort by Nth key
    -t<S>  field separator
```

## Examples
```sh
# Sort by directory sizes.
du -sh * | sort -h
```

```sh
# Sort numeric by second key.
# The default key separator is non-blank to blank transition.
echo 'a 4
d 10
c 21' | sort -k2 -n

# Sort numeric by second key, split at comma.
echo 'a,4
d,10
c,21' | sort -k2 -n -t,
```
> Use `--debug` to annotate part of the line used to sort and hence debug the key usage.