| external help file | PSCompression.dll-Help.xml |
|---|---|
| Module Name | PSCompression |
| online version | https://github.com/santisq/PSCompression |
| schema | 2.0.0 |
The Compress-TarArchive cmdlet creates a compressed tar archive file from one or more specified files or directories. It supports multiple compression algorithms and provides flexible file inclusion and exclusion options, similar to the Compress-ZipArchive cmdlet in this module.
Compress-TarArchive
[-Path] <String[]>
[-Destination] <String>
[-Algorithm <Algorithm>]
[-CompressionLevel <CompressionLevel>]
[-Force]
[-PassThru]
[-Exclude <String[]>]
[<CommonParameters>]Compress-TarArchive
-LiteralPath <String[]>
[-Destination] <String>
[-Algorithm <Algorithm>]
[-CompressionLevel <CompressionLevel>]
[-Force]
[-PassThru]
[-Exclude <String[]>]
[<CommonParameters>]The Compress-TarArchive cmdlet creates a tar archive, optionally compressed with algorithms like gzip, bzip2, zstd, or lz4, in a PowerShell-native environment. It simplifies file and directory archiving by integrating seamlessly with PowerShell’s object-oriented pipeline, allowing flexible file selection through cmdlets like Get-ChildItem or Get-Item. With support for selective exclusion via -Exclude, customizable compression levels, and the ability to overwrite existing archives, it provides a convenient alternative to traditional tar utilities for PowerShell users, while preserving directory structures and metadata.
Get-ChildItem C:\Logs -Recurse -Filter *.log |
Compress-TarArchive -Destination C:\Archives\logs.tar.gzThis example demonstrates how to compress all .log files in the C:\Logs directory into a gzip-compressed tar archive named logs.tar.gz in the C:\Archives directory.
Note
If not specified, the cmdlet uses the gzip algorithm as default.
Compress-TarArchive -Path . -Destination myPath.tar.gz -CompressionLevel FastestThis example shows how to compress the current directory (.) into a gzip-compressed tar archive named myPath.tar.gz using the Fastest compression level for quicker processing.
Compress-TarArchive -Path .\Path -Destination dest.tar.gz -ForceThis example illustrates how to create a new tar archive named dest.tar.gz from the path directory, overwriting any existing archive with the same name using the -Force parameter.
Compress-TarArchive -Path .\Path -Destination myPath.tar.gz -Exclude *.xyz, *\test\*This example shows how to compress all items in path excluding all files having a .xyz extension, any folder named test and all its child items.
Tip
The -Exclude parameter supports wildcard patterns. Exclusion patterns are tested against each item's .FullName property.
Compress-TarArchive -Path .\data -Destination C:\Backups\data.tar.bz2 -Algorithm bz2This example demonstrates how to compress the data directory into a bzip2-compressed tar archive named data.tar.bz2 in the C:\Backups directory using the bz2 algorithm.
Specifies the compression algorithm to use when creating the tar archive. Supported algorithms include gz, bz2, zst, lz, and none (no compression).
Note
If not specified, the archive is created using the gzip algorithm (gz).
Type: Algorithm
Parameter Sets: (All)
Aliases:
Accepted values: gz, bz2, zst, lz, none
Required: False
Position: Named
Default value: gz
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the compression level for the selected algorithm, balancing speed and file size. The default is algorithm-dependent but typically Optimal.
Type: CompressionLevel
Parameter Sets: (All)
Aliases:
Accepted values: Optimal, Fastest, NoCompression, SmallestSize
Required: False
Position: Named
Default value: Optimal
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the path to the tar archive output file. The destination must include the file name and either an absolute or relative path.
Note
If the file name lacks an extension, the -Algorithm parameter determines the extension is appended (e.g., .tar.gz for gz, .tar for none).
Type: String
Parameter Sets: (All)
Aliases: DestinationPath
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies an array of string patterns to exclude files or directories from the archive. Matching items are excluded based on their .FullName property. Wildcard characters are supported.
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: TrueOverwrites the destination tar archive if it exists, creating a new one. All existing entries are lost.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the exact path or paths to the files or directories to include in the archive file. Unlike the -Path parameter, the value of -LiteralPath is used exactly as typed, with no wildcard character interpretation.
Type: String[]
Parameter Sets: LiteralPath
Aliases: PSPath
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: FalseOutputs a FileInfo object representing the created tar archive. By default, the cmdlet produces no output.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the path or paths to the files or directories to include in the archive file. To specify multiple paths and include files from multiple locations, use commas to separate the paths. This parameter accepts wildcard characters, allowing you to include all files in a directory or match specific patterns.
Tip
Using wildcards with a root directory affects the archive's contents:
- To create an archive that includes the root directory and all its files and subdirectories, specify the root directory without wildcards. For example:
-Path C:\Reference - To create an archive that excludes the root directory but includes all its files and subdirectories, use the asterisk (
*) wildcard. For example:-Path C:\Reference\* - To create an archive that only includes files in the root directory (excluding subdirectories), use the star-dot-star (
*.*) wildcard. For example:-Path C:\Reference\*.*
Type: String[]
Parameter Sets: Path
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: TrueThis cmdlet supports the common parameters. For more information, see about_CommonParameters.
You can pipe strings containing paths to files or directories. Output from Get-ChildItem or Get-Item can be piped to this cmdlet.
By default, this cmdlet produces no output.
When the -PassThru switch is used, this cmdlet outputs a FileInfo object representing the created tar archive.
This cmdlet is designed to provide a PowerShell-native way to create tar archives with flexible compression options. It integrates seamlessly with other PowerShell cmdlets for file manipulation and filtering.