A command-line tool that removes content from the start of files - the opposite of truncate. Perfect for managing log files, trimming data files, and working with large text files where you want to keep the most recent content.
The word "lop" means to cut or chop off, especially from the beginning. While truncate cuts from the end, lop removes from the start - keeping the freshest data at the bottom of your files.
This tool was generated by AI.
- ๐ช Remove lines from the start of files
- ๐ Remove bytes from the start of files
- ๐ฆ Trim files to a specific target size
- ๐ In-place file editing
- ๐ Preserves file permissions
- ๐ฏ Multiple file processing
git clone https://github.com/yourusername/lop.git
cd lop
make installDo you trust me?
lop [OPTIONS] [FILE...]
If no FILE is specified, lop reads from stdin.
-n <number>- Number of lines to remove from start (default: 10)-c <bytes>- Number of bytes to remove from start (overrides-n)-s <size>- Target size for file - removes from start until file is this size-v- Show version-h- Show help
When using -s, you can specify sizes with the following suffixes:
K= 1024 bytes (KiB)M= 1024K (MiB)G= 1024M (GiB)KB= 1000 bytesMB= 1000KBGB= 1000MB- No suffix = exact bytes
# Remove first 10 lines (default)
lop application.log
# Remove first 100 lines
lop -n 100 application.log
# Remove first 5 lines from multiple files
lop -n 5 *.log# Remove first 1KB
lop -c 1024 datafile.bin
# Remove first 100 bytes
lop -c 100 file.txt# Keep only the last 1MB of a log file
lop -s 1M application.log
# Trim file to exactly 500KB
lop -s 500K largefile.dat
# Trim to 10GB (useful for huge files)
lop -s 10G database.dump
# Trim to exactly 1000 bytes
lop -s 1000 file.txt# Remove first 5 lines from stdin
cat file.txt | lop -n 5
# Use with other commands
grep "ERROR" app.log | lop -n 20 | less
# Remove header from CSV
cat data.csv | lop -n 1 > data_no_header.csvKeep your log files at a manageable size by removing old entries from the top:
# Keep only the last 10MB of logs
lop -s 10M /var/log/application.logRemove old data while keeping recent entries:
# Keep last 1000 lines
lop -n 5000 data.txt # if file has 6000 linesRemove headers or skip initial data:
# Skip CSV header
lop -n 1 data.csv
# Remove file metadata/header bytes
lop -c 512 binaryfile.datQuickly reduce file sizes without losing recent data:
# Trim all logs in a directory to 1MB each
for f in /var/log/*.log; do lop -s 1M "$f"; donelop works by:
- Reading the input file or stdin
- Skipping the specified number of lines/bytes from the start
- Copying 1MB chunks from the offset to the start of the file
- When using
-s,lopcalculates the current file size and determines how many bytes to offset from the start to reach the target size - When using
-n,lopfinds the offset for the line N+1
| Tool | Purpose | Keeps |
|---|---|---|
tail |
Show end of file | Last N lines (doesn't modify) |
head |
Show start of file | First N lines (doesn't modify) |
truncate |
Shrink file | Beginning of file |
lop |
Shrink file | End of file |
lop is designed for efficiency:
- Uses buffered I/O for fast processing
- Minimal memory footprint
- Suitable for large files (GBs)
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.