COMPACT - CMD
Overview
The COMPACT command is a versatile Windows CMD utility used to display and alter the compression state of files and directories on NTFS partitions. It is particularly useful for conserving disk space on systems where storage capability is limited. Efficient in both personal and professional settings, COMPACT can also improve the read performance on devices where disk read speed is slower than decompression speed.
Syntax
The basic syntax for using the COMPACT command is as follows:
COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]
/C: Compresses the specified files. Directories will be marked so that files added afterward will be compressed./U: Uncompresses the specified files. Directories will be marked so that files added afterward will not be compressed./S[:dir]: Applies the command to the files in the specified directory and all its subdirectories. If no directory is specified, it defaults to the current directory./A: Displays files with the hidden or system attributes./I: Ignores errors./F: Forces the compression or decompression of the specified files./Q: Reports only the most essential information.
Options/Flags
- /C: Compress the specified files and set the directory to compress new files by default.
- /U: Decompress the specified files and set the directory to not compress new files.
- /S: Recursive operation, optionally specifying a directory to start with, which is useful for comprehensive organizational tasks.
- /A: Useful when dealing in system directories or with files that are typically hidden from standard directory views.
- /I: This option suppresses error messages, suitable for scripting environments to avoid halting batch jobs.
- /F: Forces actions on files that might otherwise be skipped due to system locks or other issues.
- /Q: Minimal verbosity, ideal for scripts or when confirmation of success is not needed.
Examples
-
Compress a single file:
COMPACT /C myfile.txtThis command compresses
myfile.txt. -
Decompress a directory recursively:
COMPACT /U /S:C:\DataThis will uncompress all files within the
C:\Datadirectory and its subdirectories. -
Compress all files in the current directory and new files by default:
COMPACT /C /SThis command applies compression to all files in the current directory and any new files that are added.
Common Issues
- Access Denied: Ensure you have the required permissions to modify the file or directory’s compression state.
- File in Use: If a file is in use by another program, compression or decompression might fail. Close the conflicting program and try again.
- Path Not Found: Verify the path is correct and accessible before executing the command.
Integration
COMPACT can be efficiently combined with other CMD tools like ROBOCOPY for handling file backups in compressed formats, enhancing storage efficiency in backup routines.
Example script to backup an uncompressed directory into a compressed backup directory:
mkdir C:\BackupDir
COMPACT /C /S:C:\BackupDir
ROBOCOPY C:\SourceDir C:\BackupDir /MIR
Related Commands
DISKPART: Useful for managing disk partitions including setting up and managing NTFS partitions.CHKDSK: Can be used to check the file system integrity of NTFS volumes whereCOMPACTis being utilized.FSUTIL: This command offers several utilities related to file systems, including managing file compression.
Further resources and official documentation are available on Microsoft’s official documentation site.