Skip to content

Commit b12648e

Browse files
committed
Add Sort In Numerical Order as a unix til
1 parent 70c0d43 commit b12648e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77
warrant a full blog post. These are mostly things I learn by pairing with
88
smart people at [Hashrocket](http://hashrocket.com/).
99

10-
_420 TILs and counting..._
10+
_421 TILs and counting..._
1111

1212
---
1313

@@ -390,6 +390,7 @@ _420 TILs and counting..._
390390
- [Securely Remove Files](unix/securely-remove-files.md)
391391
- [SSH Escape Sequences](unix/ssh-escape-sequences.md)
392392
- [SSH With Port Forwarding](unix/ssh-with-port-forwarding.md)
393+
- [Sort In Numerical Order](unix/sort-in-numerical-order.md)
393394
- [Switch Versions of a Brew Formula](unix/switch-versions-of-a-brew-formula.md)
394395
- [View A Web Page In The Terminal](unix/view-a-web-page-in-the-terminal.md)
395396
- [Watch The Difference](unix/watch-the-difference.md)

unix/sort-in-numerical-order.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Sort In Numerical Order
2+
3+
By default, the `sort` command will sort things alphabetically. If you have
4+
numerical input though, you may want a numerical sort. This is what the `-n`
5+
flag is for.
6+
7+
If I have a directory of files with numbered names, sort doesn't quite do
8+
the job by itself.
9+
10+
```bash
11+
$ ls | sort
12+
1.txt
13+
10.txt
14+
11.txt
15+
12.txt
16+
2.txt
17+
3.txt
18+
4.txt
19+
5.txt
20+
```
21+
22+
with the `-n` flag, I get the sort order I am looking for.
23+
24+
```bash
25+
$ ls | sort -n
26+
1.txt
27+
2.txt
28+
3.txt
29+
4.txt
30+
5.txt
31+
10.txt
32+
11.txt
33+
12.txt
34+
```

0 commit comments

Comments
 (0)