Compress (trim) a file from the beginning on linux

Is it possible in Linux (and / or in another Unix) to compress a file from the very beginning? I would like to use it for a constant queue (no existing implementation meets my needs). From the end of the file, I assume this is possible with truncate ().

+6
file truncate
source share
3 answers

If you are using ext4, xfs or some other modern file system starting with Linux Kernel 3.15, you can use:

#include <fcntl.h> int fallocate(int fd, int mode, off_t offset, off_t len); 

with the flag FALLOC_FL_COLLAPSE_RANGE .

http://manpages.ubuntu.com/manpages/disco/en/man2/fallocate.2.html

0
source share

Yes, you can use cut or tail to delete parts of the file.

cut -b 17- input_file
tail -c +17 input_file

This outputs the contents of the input file starting at the 17th byte, effectively deleting the first 16 bytes of the file. Note that the cut example will also add a new line for output.

-2
source share

I have a truncated file specified as an argument of 64,000,000 bytes using the following Python script:

 #!/usr/bin/env python import sys import os file = sys.argv[1] f = os.open(file, os.O_RDWR) os.ftruncate(f, 64000000) os.close(f) 
-5
source share

All Articles