Skip to content

Commit 5e63e42

Browse files
committed
Add Output The Last N Bytes Of A Large File as a Unix TIL
1 parent 129cd11 commit 5e63e42

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1337 TILs and counting..._
13+
_1338 TILs and counting..._
1414

1515
---
1616

@@ -1318,6 +1318,7 @@ _1337 TILs and counting..._
13181318
- [Occupy A Local Port With Netcat](unix/occupy-a-local-port-with-netcat.md)
13191319
- [Only Show The Matches](unix/only-show-the-matches.md)
13201320
- [Open The Current Command In An Editor](unix/open-the-current-command-in-an-editor.md)
1321+
- [Output The Last N Bytes Of A Large File](unix/output-the-last-n-bytes-of-a-large-file.md)
13211322
- [Partial String Matching In Bash Scripts](unix/partial-string-matching-in-bash-scripts.md)
13221323
- [PID Of The Current Shell](unix/pid-of-the-current-shell.md)
13231324
- [Print A Range Of Lines For A File With Bat](unix/print-a-range-of-lines-for-a-file-with-bat.md)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Output The Last N Bytes Of A Large File
2+
3+
After creating a massive JSON file as part of a data export, I wanted to check
4+
the timestamp of the last value in the file. However, even for Vim, the file
5+
was big and it was taking a while to bring the whole thing into memory.
6+
7+
I didn't really need to open it in a full-fledged editor, I just needed to grab
8+
the trailing bits (bytes!) of the file until I could see enough data to verify
9+
the export.
10+
11+
The `tail` command is a great tool for this because it can quickly read
12+
information from the end of a file. The `-c` flag in particular allows you to
13+
grab the last N bytes of the file and output them.
14+
15+
So, I started with:
16+
17+
```bash
18+
$ tail -c 100 data.json
19+
```
20+
21+
That didn't quite show me enough info, so I bumped it up:
22+
23+
```bash
24+
$ tail -c 1000 data.json
25+
```
26+
27+
That time I was able to see enough to verify the export.
28+
29+
Both commands ran instantaneously, meanwhile my editor was still opening the
30+
file.
31+
32+
See `man tail` for more details.

0 commit comments

Comments
 (0)