Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to be able to compress certain files (that I need to keep, but use rarely) on disk. I noticed that chattr +c flags a file for compression, but it doesn't seem to actually compress files.

What is the simplest way to implement file compression on a per-file or per-directory basis?

share|improve this question
    
Write a kernel module that does so. –  Ignacio Vazquez-Abrams Nov 13 '13 at 15:44
    
Compress them manually? –  HBruijn Nov 13 '13 at 18:49
    
Transparent file system compression –  Angelo Nov 13 '13 at 21:04

2 Answers 2

up vote 2 down vote accepted

Ext2 and family (including ext4) reserve an attribute for compression but don't implement it. This feature was originally put off because there were more urgent things to do, and then it became obsolescent as the size of storage media increased a lot faster than the size of data that isn't already compressed. Most large files today (videos, music, even word processor documents) are already compressed.

Compression can still make sense for medium-sized files. Performance-wise, it's a trade-off: it costs more CPU time but less I/O time.

Zfs includes everything but the kitchen sink, and in particular it does support compression. So does Linux's btrfs.

share|improve this answer

You could create a container file that contains a filesystem providing compression (like zfs). It's not very flexible but pretty simple and probably set up within a few minutes.

Just google for luks and container to find how to work with container files. Replacing the luks stuff with your favourite filesystem should be rather simple.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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