How To Compress Files and Folders In File System Level With Compact Command In Windows NTFS?
Windows modern file system NTFS provides some compression mechanisms to gain more space in disks and partitions. This compression operation is done mainly with
compact command. This command do not directly compress the files as we stated in the start compression operation is done by NTFS file system in the file system level. So we do not see any change in the file and folder names and behaviours. This command simply change file system related compression attributes and the compression will be done by operating system file system part in a appropriate time automatically.
compact command can be printed like below.
$ compact /?
Syntax of the
compact command is very same with the most the windows commands.
compact [option] [file/directory]
Display Compression Information
We may need the current situation of the working directory compression status. We will get information about compressed files, the compression ratio and how much space we have gained from file system level compression. We will only issue the
compact command to list current directory compression information like below.
As we can see all files size information like before compression and after compression is listed. In this example we can clearly see that there is no compressed file. We can understand this from compression ratio which is
1.0 for all files.
Ratio is used to score space saving in number. Higher ratio means more spaces and savings in our disk. We want to save a lot of space in our disks. We can not change the ratio in a easy way. Ratio is determined by files data types.
Following files have more compressible data
- Office Document
- Recurring Data
Following files have less compressible data
The first example about compression is compressing a single file. This command will set the files compress attributes true. We will use
/C option to compress given file.
$ compact /c users.txt
We can see from output the current size of the file which is
47 byte and the compression ratio which is
1 because we recently set to compress.
Compress All Files
We can set enable the compression for all current working directory files by using
* (asterisk) for file name. This will assume the command will be executed for all files.
$ compact /c *
Compress All Files and Sub Directory Files
Compression attrbutes can be set enable for a given directories all sub directories and folders with
/s option. We call this recursively. This is the most used version of the compact command. This option gives the ability to work and compress files as a bulk.
In this example we will compress all sub-directories and files in
cygwin64 directory in a recursive manner.
$ compact /s /c cygwin64
After issuing command the command is executed in a recursive manner as we can see from output.
Up to now we have compressed or set the compression attributes of the files. In some situations compression by file system can create some headache for us. So we may need to disable the file system level compression for a file. We can disable compression for a file by providing the
/u option like below.
In this example we will turn off compression for file named
$ compress /u users.txt
Uncompress All Files
We can also turn off compression for all files in the current working directory too.
$ compress /u *
Uncompress All Files and Sub Directory Files
We can also change the compression attributes of all files currently located in current working directory and childs as recursively. We can accomplish this task like below.
$ compress /u /s *