mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Output The Last N Bytes Of A Large File as a Unix TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1337 TILs and counting..._
|
_1338 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -1318,6 +1318,7 @@ _1337 TILs and counting..._
|
|||||||
- [Occupy A Local Port With Netcat](unix/occupy-a-local-port-with-netcat.md)
|
- [Occupy A Local Port With Netcat](unix/occupy-a-local-port-with-netcat.md)
|
||||||
- [Only Show The Matches](unix/only-show-the-matches.md)
|
- [Only Show The Matches](unix/only-show-the-matches.md)
|
||||||
- [Open The Current Command In An Editor](unix/open-the-current-command-in-an-editor.md)
|
- [Open The Current Command In An Editor](unix/open-the-current-command-in-an-editor.md)
|
||||||
|
- [Output The Last N Bytes Of A Large File](unix/output-the-last-n-bytes-of-a-large-file.md)
|
||||||
- [Partial String Matching In Bash Scripts](unix/partial-string-matching-in-bash-scripts.md)
|
- [Partial String Matching In Bash Scripts](unix/partial-string-matching-in-bash-scripts.md)
|
||||||
- [PID Of The Current Shell](unix/pid-of-the-current-shell.md)
|
- [PID Of The Current Shell](unix/pid-of-the-current-shell.md)
|
||||||
- [Print A Range Of Lines For A File With Bat](unix/print-a-range-of-lines-for-a-file-with-bat.md)
|
- [Print A Range Of Lines For A File With Bat](unix/print-a-range-of-lines-for-a-file-with-bat.md)
|
||||||
|
|||||||
32
unix/output-the-last-n-bytes-of-a-large-file.md
Normal file
32
unix/output-the-last-n-bytes-of-a-large-file.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Output The Last N Bytes Of A Large File
|
||||||
|
|
||||||
|
After creating a massive JSON file as part of a data export, I wanted to check
|
||||||
|
the timestamp of the last value in the file. However, even for Vim, the file
|
||||||
|
was big and it was taking a while to bring the whole thing into memory.
|
||||||
|
|
||||||
|
I didn't really need to open it in a full-fledged editor, I just needed to grab
|
||||||
|
the trailing bits (bytes!) of the file until I could see enough data to verify
|
||||||
|
the export.
|
||||||
|
|
||||||
|
The `tail` command is a great tool for this because it can quickly read
|
||||||
|
information from the end of a file. The `-c` flag in particular allows you to
|
||||||
|
grab the last N bytes of the file and output them.
|
||||||
|
|
||||||
|
So, I started with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ tail -c 100 data.json
|
||||||
|
```
|
||||||
|
|
||||||
|
That didn't quite show me enough info, so I bumped it up:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ tail -c 1000 data.json
|
||||||
|
```
|
||||||
|
|
||||||
|
That time I was able to see enough to verify the export.
|
||||||
|
|
||||||
|
Both commands ran instantaneously, meanwhile my editor was still opening the
|
||||||
|
file.
|
||||||
|
|
||||||
|
See `man tail` for more details.
|
||||||
Reference in New Issue
Block a user