# 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

• 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.
{"extraction_info": {"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.890384316444397, "perplexity": 5406.405675864848}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2017-26/segments/1498128323807.79/warc/CC-MAIN-20170628222452-20170629002452-00169.warc.gz"}