Quantcast
Channel: How to cut a file to a given size under Linux? - Super User
Viewing all articles
Browse latest Browse all 6

How to cut a file to a given size under Linux?

$
0
0

I want to shrink a file's size by brute-force, that is, I don't care about the rest, I just want to cut the file, say by half, and discard the rest.

The first thing that comes to mind is Perl's truncate. I'm following the example on that page and did the exactly the same thing:

seq 9 > test.txtls -l test.txtperl -we 'open( FILE, "< ./test.txt" ) && truncate( FILE, 8 ) && close(FILE);'

But the file still has the same size:

$ ls -lgG test.txt-rw-rw---- 1 18 2013-08-08 09:49 test.txt

How can I make this work?


Viewing all articles
Browse latest Browse all 6

Trending Articles