≡ Menu

Compact : compress files from command line (CMD)

Windows built-in command compact allows one to compress or un-compress files on a NTFS file system. Using this command we can set compression attributes on a directory also so that the new files added to the directory will be compressed automatically.Let’s see the syntax of the command ‘compact‘ with few examples.

Check the compression status of a file:

compact filename

Example:

C:\docs>compact mydoc.txt
Listing C:\docs\
New files added to this directory will not be compressed.
2779705 :   2779705 = 1.0 to 1   mydoc.txt
Of 1 files within 1 directories
0 are compressed and 1 are not compressed.
2,779,705 total bytes of data are stored in 2,779,705 bytes.
The compression ratio is 1.0 to 1.

Compress a file from command line:

compact /c filename

Example:

C:\docs>compact /c mydoc.txt
Compressing files in C:\docs\
mydoc.txt             2779705 :    348160 = 8.0 to 1 [OK] 
1 files within 1 directories were compressed. 
2,779,705 total bytes of data are stored in 348,160 bytes. 
The compression ratio is 8.0 to 1.

Uncompress a file:

compact /u filename

example:

C:\docs>compact /u mydoc.txt
Uncompressing files in C:\docs\
mydoc.txt [OK]
1 files within 1 directories were uncompressed.

To compress all the files in the current directory

compact /c *

To compress all the files in the current directory and also the sub directories and the files within them recursively

compact /c /s *

To un-compress all the files in the current directory

compact /u *

To un-compress all the files in the current directory and also in its sub directories:

compact /u /s *

Related Posts:
Understanding NTFS compression

3 comments… add one
  • wanttoknow

    how did you make the compression ratio to 8.0 to 1

    • Zoner Zaner

      can you show how to increase the max compression to a different amount?

  • José Oliveira

    Very nice!!! Thank you man!!! Great job!
    Continue to share knowledge!!!

    Regards.

Leave a Comment