≡ 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

10 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?

  • Paul

    Use ‘compact /?’ to find out more details on the command.
    the compression ratio will depend on the file type I suspect, text compressing more than pictures for example.

  • Fatima zahra Bouj

    but why i get that error:
    ‘compact’ n’est pas reconnu en tant que commande interne ou externe ….
    ???

  • naresh

    Can we compress into .ZIP file in cmd without using powershell or vbscripts ?

  • Pranav Kulkarni

    I have used the same command it has run successfully but when i checked the size of my compressed file it shows same as previous

  • Anshu Kumar

    Where is my Compact file? I am not able to find it on my drive. Please guide.

  • Uncle J

    Please everybody, be aware that this Compact is a bit like the old Drivespace in DOS: it does NOT create a NEW file, like a zip file, but it stores the same file, or the whole directory, in a compressed manner. In NTFS. Because NTFS has the ability to do that, and FAT / FAT32 cannot. Your Compressed file will only take less disk space when stored on that disk it was Compressed on. And I don’t know if that Compression attribute follows along when that file is copied to another (NTFS) disk.

    It is possible to select so that compressed files show up in another colour in file explorer, for your convenience. And be aware that compaction ratios aren’t that impressive.

    The practical use of Compress is less nowadays as we collect lots of images and sound and these can’t be compacted more, and Compress is a tradeoff between process speed and file size. Imagine compressing a database file? Great – it has to be unravelled and recompressed by Windows each time you make a record change.
    Allegedly Compress works / (worked?) good with CAD programs where you have huge parts libraries with thousands of small component files.

    In the best of worlds you can compress your Documents directory and %programfiles% to save disks space. But allegedly Compress interferes with windowsupdate.

  • Patty

    Why are you trying to uncompress a .txt file????

  • Simon

    Hi. You can use a free online tool to create RAR https://freetools.site/file-compressor/rar

Leave a Comment