1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-04 23:58:01 +00:00

Add Sort In Numerical Order as a unix til

This commit is contained in:
jbranchaud
2016-05-18 19:13:04 -05:00
parent 70c0d43e97
commit b12648eb89
2 changed files with 36 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
# Sort In Numerical Order
By default, the `sort` command will sort things alphabetically. If you have
numerical input though, you may want a numerical sort. This is what the `-n`
flag is for.
If I have a directory of files with numbered names, sort doesn't quite do
the job by itself.
```bash
$ ls | sort
1.txt
10.txt
11.txt
12.txt
2.txt
3.txt
4.txt
5.txt
```
with the `-n` flag, I get the sort order I am looking for.
```bash
$ ls | sort -n
1.txt
2.txt
3.txt
4.txt
5.txt
10.txt
11.txt
12.txt
```