1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-09 01:58:02 +00:00

Add Output The Last N Bytes Of A Large File as a Unix TIL

This commit is contained in:
jbranchaud
2023-09-19 16:43:16 -05:00
parent 129cd11940
commit 5e63e420bc
2 changed files with 34 additions and 1 deletions

View 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.