penguinpowernz/lop

A command-line tool that removes content from the start of files - the opposite of truncate

โ˜… 0Forks 0GoGitHub โ†—Compare

README

lop

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.

Why "lop"?

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.

WARNING: AI SLOP

This tool was generated by AI.

Features

  • ๐Ÿ”ช 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

Installation

From Source

git clone https://github.com/yourusername/lop.git
cd lop
make install

From Github

Do you trust me?

Usage

lop [OPTIONS] [FILE...]

If no FILE is specified, lop reads from stdin.

Options

  • -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

Size Suffixes

When using -s, you can specify sizes with the following suffixes:

  • K = 1024 bytes (KiB)
  • M = 1024K (MiB)
  • G = 1024M (GiB)
  • KB = 1000 bytes
  • MB = 1000KB
  • GB = 1000MB
  • No suffix = exact bytes

Examples

Remove Lines

# 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 Bytes

# Remove first 1KB
lop -c 1024 datafile.bin

# Remove first 100 bytes
lop -c 100 file.txt

Trim to Target Size

# 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

Pipeline Operations

# 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.csv

Use Cases

Log File Management

Keep 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.log

Rotating Files

Remove old data while keeping recent entries:

# Keep last 1000 lines
lop -n 5000 data.txt  # if file has 6000 lines

Data Processing

Remove headers or skip initial data:

# Skip CSV header
lop -n 1 data.csv

# Remove file metadata/header bytes
lop -c 512 binaryfile.dat

Disk Space Management

Quickly 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"; done

How It Works

lop works by:

  1. Reading the input file or stdin
  2. Skipping the specified number of lines/bytes from the start
  3. Copying 1MB chunks from the offset to the start of the file
  • When using -s, lop calculates the current file size and determines how many bytes to offset from the start to reach the target size
  • When using -n, lop finds the offset for the line N+1

Comparison with Similar Tools

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

Performance

lop is designed for efficiency:

  • Uses buffered I/O for fast processing
  • Minimal memory footprint
  • Suitable for large files (GBs)

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Contributors

penguinpowernz

Issues