1

I have a compressed file, and on compression or decompression, I want to get it's final compressed size (for compression) or original compressed size (for decompression).

I have used wc -c before:

$time xz -fc inputfile.tar | wc -c
1318524
2.132

However, the execution time is significantly more since I am still writing file to disk, instead of when I am using redirect to /dev/null:

$ time xz -fc inputfile.tar > /dev/null
1.671

How do I get compressed size (1318524) with final redirection of data to /dev/null?

  • xz --verbose will print stats (unfortunately human readable format) – rudimeier Sep 1 '16 at 4:43
  • I suspect this may be a pretty bad idea since you'll probably want to run the operation again which will take more resources than the disk speed and usage limitations would save. – Julie Pelletier Sep 1 '16 at 4:48
  • Have you try to use ls after the compression to get size of resulting file? – Romeo Ninov Sep 1 '16 at 7:21
  • time xz -fc inputfile.tar | wc -c doesn't write anything to disk... – Stephen Kitt Sep 1 '16 at 8:46
  • It still takes longer to execute. Maybe because it opens another process for wc. I kind of solve my problem by running same command again, first to get time and then CR. But of course its not ideal. – Armen Sep 1 '16 at 22:42
1

Instead of xz operating on a file, you should make it operate on the stdin stream. This will get you the file size without writing data:

cat inputfile.tar | xz -c | wc -c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.