mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Sort In Numerical Order as a unix til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
||||
warrant a full blog post. These are mostly things I learn by pairing with
|
||||
smart people at [Hashrocket](http://hashrocket.com/).
|
||||
|
||||
_420 TILs and counting..._
|
||||
_421 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -390,6 +390,7 @@ _420 TILs and counting..._
|
||||
- [Securely Remove Files](unix/securely-remove-files.md)
|
||||
- [SSH Escape Sequences](unix/ssh-escape-sequences.md)
|
||||
- [SSH With Port Forwarding](unix/ssh-with-port-forwarding.md)
|
||||
- [Sort In Numerical Order](unix/sort-in-numerical-order.md)
|
||||
- [Switch Versions of a Brew Formula](unix/switch-versions-of-a-brew-formula.md)
|
||||
- [View A Web Page In The Terminal](unix/view-a-web-page-in-the-terminal.md)
|
||||
- [Watch The Difference](unix/watch-the-difference.md)
|
||||
|
||||
34
unix/sort-in-numerical-order.md
Normal file
34
unix/sort-in-numerical-order.md
Normal 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
|
||||
```
|
||||
Reference in New Issue
Block a user