Compression & Archiving
Commands for compressing and decompressing files with gzip, and creating or extracting archives with tar.
Compress files using the gzip format. By default, replaces each file with a compressed .gz version.
Syntax
Section titled “Syntax”gzip [OPTIONS] FILE...| Flag | Description |
|---|---|
-d | Decompress (same as gunzip) |
-c | Write output to stdout instead of replacing the file |
-k | Keep the original file (do not delete after compress/decompress) |
-f | Force overwrite of output files |
-v | Verbose — show compression ratio for each file |
-l | List compression statistics instead of compressing |
-1 .. -9 | Compression level (-1 fastest, -9 smallest, default -6) |
Return type
Section titled “Return type”With -l, each result is a PsBash.GzipListOutput object:
| Property | Type | Description |
|---|---|---|
CompressedSize | int | Size of the compressed file in bytes |
UncompressedSize | int | Original uncompressed size in bytes |
Ratio | string | Compression ratio as a percentage (e.g. "72.5%") |
FileName | string | Path to the compressed file |
BashText | string | Formatted text output |
With -v, returns BashObject lines showing the compression ratio per file.
Examples
Section titled “Examples”# Compress a file, keeping the originalgzip -k data.csv# Compress with maximum compressiongzip -9 largefile.bin# List compression statistics for a .gz filegzip -l archive.gz# Access typed properties from the list output$info = gzip -l backup.gz$info.CompressedSize # 14320$info.UncompressedSize # 52480$info.Ratio # "72.7%"gunzip
Section titled “gunzip”Decompress gzip-compressed files. This is an alias for gzip -d — it automatically sets the decompress flag.
Syntax
Section titled “Syntax”gunzip [OPTIONS] FILE...| Flag | Description |
|---|---|
-c | Write decompressed output to stdout |
-k | Keep the .gz file after decompression |
-f | Force overwrite of output files |
-v | Verbose — show compression ratio |
Examples
Section titled “Examples”# Decompress a file, removing the .gzgunzip data.csv.gz# Decompress but keep the original .gz filegunzip -k archive.gz# Decompress to stdout for pipinggunzip -c logs.gz | grep 'ERROR'Decompress gzip files and write the content to stdout. This is equivalent to gzip -dc — both decompress and stdout flags are set automatically.
Syntax
Section titled “Syntax”zcat FILE...Examples
Section titled “Examples”# View compressed file contentszcat readme.txt.gz# Pipe decompressed content into other commandszcat access.log.gz | grep '404' | wc -l# Preview the first few lines of a compressed filezcat data.csv.gz | head 5Create, extract, and list archive files. Uses System.IO.Compression.ZipArchive internally, with optional gzip wrapping via the -z flag.
Syntax
Section titled “Syntax”tar [OPTIONS] [FILE...]| Flag | Description |
|---|---|
-c | Create a new archive |
-x | Extract files from an archive |
-t | List the contents of an archive |
-f FILE | Specify the archive filename (required) |
-z | Filter the archive through gzip (compress on create, decompress on extract/list) |
-v | Verbose — print filenames as they are processed |
-C DIR | Change to DIR before extracting |
--exclude=PATTERN | Exclude files matching the glob pattern |
Return type
Section titled “Return type”With -t, each entry is a PsBash.TarListOutput object:
| Property | Type | Description |
|---|---|---|
Name | string | Filename within the archive |
Size | long | Uncompressed size in bytes |
ModifiedDate | DateTime | Last modification timestamp |
BashText | string | Entry path as displayed in the listing |
Examples
Section titled “Examples”# Create a gzip-compressed archive from a directorytar -czf project.tar.gz src/# Extract a gzip-compressed archive to a specific directorytar -xzf project.tar.gz -C /tmp/output# List contents of an archivetar -tzf backup.tar.gz# Access typed properties from the listing$entries = tar -tzf project.tar.gz$entries[0].Name # "app.js"$entries[0].Size # 2048$entries[0].ModifiedDate # 4/1/2026 3:22:00 PM# Create an archive excluding test filestar -czf release.tar.gz src/ --exclude=*.test.ps1# Verbose extract to see each file as it is writtentar -xzvf archive.tar.gz