File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77warrant a full blog post. These are mostly things I learn by pairing with
88smart 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 )
Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments