8.4.17 gzip command (compresses files or decompresses compressed files)
Syntax
- [Only for Windows]
-
gzip [-1|-2|-3|-4|-5|-6|-7|-8|-9] [-c] [-d] [-f] [-k] [-l] [-N] [-n] [-q] [-r] [-t] [-v] [-o output-path-name] [-S suffix] [target-path-name ...]
- [Only for UNIX]
-
gzip [-1|-2|-3|-4|-5|-6|-7|-8|-9] [-a] [-c] [-d] [-f] [-k] [-l] [-N] [-n] [-q] [-r] [-t] [-v] [-o output-path-name] [-S suffix] [target-path-name ...]
Description
This command compresses files or decompresses compressed files.
This command enables you to perform the following operations:
Operation type |
Description |
---|---|
Compress |
Compresses a file (hereafter, this operation is called a compression operation). If the -d, -l, and -t options are omitted, a compression operation is performed. The format of the compressed file is gzip (hereafter, files compressed in gzip format are called "compressed files"). Compresses the file data by using the DEFLATE compression method# (hereafter, compressed file data is called "compressed data"). The compressed data is stored in the compressed file that was created by the compression operation. In a compression operation, the compressed file is created with the extension .gz appended to the name of the file to be compressed. In a compression operation, the file to be compressed is deleted after the compressed file is created. |
Decompress |
Decompresses a compressed file when the -d option is specified (hereafter, this operation is called a decompression operation). Only files compressed in gzip format can be decompressed. The system assumes files with .gz or .tgz extensions are compressed files. Files that are not compressed in gzip format or those without .gz or .tgz extensions cannot be decompressed. In a decompression operation, the decompressed file is created under a name whose character string is generated as follows:
In a decompression operation, the compressed file is deleted after the decompressed file is created. |
Display |
Displays the information about the compressed file when the -l option is specified (hereafter, this operation is called a display operation). For details about the displayed information of compressed files, see the description of the -l and -v options, as well as Displaying the compressed file information. |
Verify |
Specifying the -t option verifies the integrity of the compressed data stored in the compressed file without decompressing the compressed file (hereafter, this operation is called a verification operation). |
- #
-
Compression method used when the file is compressed in gzip format.
In compression operations and decompression operations, if you do not want to delete the files to be compressed or the compressed files, perform one of the following operations:
-
Output the compression result and the decompression result to the standard output.
The following operation outputs the compressed or decompressed file data to the standard output without deleting the files. As required, redirect the output results to files or send them to other programs by using a pipe.
-
Specify the -c option.
-
Enter the files to be compressed or the compressed file from the standard input.
-
-
Specify the -k option.
If this command is executed by specifying the -k option, the system behaves as follows:
- [For compression operations]
-
Files to be compressed are not deleted even after the compressed file is created.
- [For decompression operations]
-
Compressed files are not deleted even after the decompressed files are created.
In compression operations and decompression operations, if an existing file has the same name as the compressed file or decompressed file to be created, the system asks whether to overwrite the file. If the response character from the standard input begins with y or Y, the system deletes the existing file, and then creates the compressed file or decompressed file. If the response character does not begin with y or Y, or when the standard input cannot be used, processing on the target files stops. If you want to permit overwriting of files without prompting, specify the -f option.
Note that directories cannot be compressed in compression operations. If you want to compress files while retaining their directory configuration, create an archive by using the tar command, and then compress that archived file. In addition, by using the -z option of the tar command, you can simultaneously create and compress the archive file. For details about the tar command, see 8.4.34 tar command (stores the target path name in the archive and extracts/displays the target path name).
Verification of the integrity of the compressed data, which is performed in the verification operation, is also performed in the decompression operation. Note that for values (information such as the compression method) other than the compressed data of the compressed file, integrity verification is performed in all operations.
You can use the options of the gzip command without specifying them in the command arguments, by specifying the options in the environment variable GZIP. For details about the environment variable GZIP, see 2.5 Specifying environment variables.
Arguments
Specifying operation options
Specify the operation to be executed.
If this command is executed without specifying the following options, the file will be compressed (compression operation):
-d
--decompress
- --uncompress
-
Decompresses the compressed file (decompression operation).
If this option is specified at the same time as the -l or -t option, the specification is ignored.
-l
- --list
-
Displays information about the compressed file (display operation).
Displays information such as the file size before compression and the compression ratio.
If the -v option is specified at the same time, detailed information about the compressed file is also displayed.
For details about the displayed content, see Displaying compressed file information.
Note that if the displayed file size before compression is 4 GB or greater, the value might not be displayed correctly. If you want to display the correct file size, specify the -t option at the same time. However, if the -t option is specified at the same time, displaying the file size might take some time.
-t
- --test
-
Verifies the integrity of the compressed data stored in the compressed file without decompressing the compressed file (verification operation).
If this option is specified at the same time as the -l option, both the integrity verification of the compressed data and the display of information about the compressed file are performed.
Specifying the compression level
-compression-level
--fast
- --best
-
When performing compression, use levels to specify the compression speed and the compression ratio.
Specify the compression level from a range of 1 to 9. The meanings of the values are as follows:
-
Compression speed
1 is the fastest, and 9 is the slowest.
As the value gets larger, the compression speed gets slower.
-
Compression ratio
1 is the lowest, and 9 is the highest.
As the value gets larger, the compression ratio gets higher.
If this option is not specified, the file is compressed using compression level 6.
The --fast option compresses the file using the same compression level as -1.
The --best option compresses the file using the same compression level as -9.
If you specify this option multiple times, the last option specified is valid.
If this option is specified at the same time as the -d, -l, or -t option, the specification is ignored.
-
Specifying behavior for saving and recovering file information
Specify behavior for saving and recovering file information.
If the -N and -n options are specified at the same time, only the last specified option is valid. If the -N or -n option is specified at the same time as the -t option, the specification is ignored.
For details about using the most recent modification date and time in compression operations and decompression operations, see Handling of the most recent access date and time or the most recent modification date and time for a file. For details about the handling of file names and the most recent modification date and time in display operations, see Displaying compressed file information.
-N
- --name
-
- [For compression operations]
-
Stores the file name and the most recent modification date and time of the file to be compressed, in the compressed file. File names to be stored in the compressed file are extracted from the path name. Note that when a file to be compressed is entered from the standard input, the execution date and time of the command is stored in the most recent modification date and time in the compressed file. However, the file name is not stored in the compressed file.
- [For decompression operations]
-
Names the file created at decompression using the file name stored in the compressed file. In addition, sets the most recent modification date and time stored in the compressed file, for the created file. If the file name and the most recent modification date and time are not stored in the compressed file, the system behaves the same as when the -n option is specified.
- [For display operations]
-
In the displayed compressed file information, displays the file name and the most recent modification date and time stored in the compressed file.
In compression operations, this option is the default behavior.
-n
- --no-name
-
- [For compression operations]
-
Does not store the file name or the most recent modification date and time of the file to be compressed, in the compressed file.
- [For decompression operations]
-
Names the file created at decompression using the file name from the compressed file, with the compressed file extension removed. In addition, sets the most recent modification date and time of the compressed file to the created file.
- [For display operations]
-
In the displayed compressed file information, displays the file name as the compressed file name with its extension removed, and the most recent modification date and time of the compressed file.
For decompression operations and display operations, this option is the default behavior.
Specifying input and output
-c
--stdout
- --to-stdout
-
- [For compression operations]
-
Outputs compressed file data to the standard output.
An error occurs if the standard output is linked with the terminal when the command is executed.
If multiple files are compressed by specifying this option, compression and output to the standard output is repeated for each file. This behavior is the same as when multiple compressed files are concatenated by using commands such as the cat command (to create a single compressed file). For notes on compressed files created by this operation, see Notes.
- [For decompression operations]
-
Outputs the result of decompressing the compressed data to the standard output.
If this option is specified at the same time as the -l or -t option, the specification is ignored.
-k
- --keep
-
- [For compression operations]
-
The original files to be compressed are not deleted even after the compressed file is created.
- [For decompression operations]
-
The compressed file is not deleted even after the decompressed file is created.
If this option is specified at the same time as the -l, -t, or -c option, the specification is ignored.
-r
- --recursive
-
If the path specified in the target-path-name is a directory, searches recursively for files in the directory and its subdirectories.
- [For compression operations]
-
Searches for files in the directory and its subdirectories that are not compressed.
- [For decompression operations, display operations, and verification operations]
-
Searches for compressed files in the directory and its subdirectories.
In Windows, when the -r option is specified, directory delimiters at the end of the path name are ignored, even when you specify a symbolic link to a directory.
The file extension determines whether files found while searching are handled as compressed files. For details about the file extensions of files that are handled as compressed files, see Handling of the extensions of compressed files.
Symbolic links to directories are followed to their destination based on the operation type and the specified options. For details about behavior when a symbolic link to a directory is specified, see Handling of link files.
-ooutput-path-name
- --output=output-path-name
-
- [For compression operations]
-
Creates a compressed file based on the specified path name.
In addition, in compression operations, the files to be compressed are deleted.
- [For decompression operations]
-
Creates the files to be decompressed based on the specified path name. In addition, in a decompression operation, the compressed file is deleted. If the -N option is specified at the same time as the decompression operation, the most recent modification date and time stored in the compressed file is used. The file name is based on the output-path-name.
This option ends in an error if one of the following is specified at the same time.
-
When the -c, -t, -l, or -r option is specified.
-
When more than one file to be compressed or compressed file is specified.
-
Enter the files to be compressed, or the compressed file, from the standard input.
- Target-path-name
-
- [For compression operations]
-
Specify the path name for the file to be compressed.
- [For decompression operations, display operations, and verification operations]
-
Specify the path name for the compressed file.
For details about specifying compressed files in compression operations, or specifying files other than compressed files in decompression operations, display operations, and verification operations, see Handling of the extensions of compressed files.
More than one target-path-name can be specified.
If the target-path-name is not specified, or when - is specified for the target-path-name, enter the file data to be compressed or the compressed data from the standard input. For compression operations and decompression operations, when the file data to be compressed or the compressed data is input from the standard input, the compressed file data or the result of decompressing the compressed data is output to the standard output. Note that in a compression operation, an error occurs if the standard output is linked to the terminal. In a decompression operation, an error occurs if the standard input is linked to the terminal.
The file types that can be specified for the target-path-name are as follows:
-
For compression operations and decompression operations, only regular files can be specified. In addition, whether link files can be specified depends on the specified options. For details about behavior when link files are specified, see Handling of link files.
-
For display operations and verification operations, regular files and link files can be specified.
-
A directory can be specified for the -r option. Whether a symbolic link to a directory can be specified depends on the operation type and the specified options. For details about behavior when a symbolic link to a directory is specified, see Handling of link files.
An error occurs if the specified target-path-name is a file type other than the file types that can be operated.
Other specifications
-a
- --ascii
-
- [Only for UNIX]
-
This option is for compatibility with the gzip command provided by the OS.
This option is not valid even if specified. However, the message gzip: Option -a is ignored on this system is output to the standard error output.
-f
- --force
-
Permits the following operations:
[For compression operations]
-
Follows the link destination in a link file. For details about link files, see Handling of link files.
-
If an existing file has the same name as the compressed file to be created, the system overwrites the file without prompting the user.
-
When the -c option is specified or when the file data to be compressed is entered from the standard input, output of the compressed file data begins even if the standard output is linked to the terminal.
[For decompression operations]
-
Follows the link destination in a link file. For details about link files, see Handling of link files.
-
If an existing file has the same name as the decompressed file to be created, the system overwrites the file without prompting the user.
-
When the file data to be operated is entered from the standard input, the input begins even if the standard input is linked to the terminal.
-
-S suffix
- --suffix= suffix
-
Uses the specified suffix (any character string) as the extension of the compressed file.
- [For compression operations]
-
Creates a compressed file using a specified suffix instead of an extension .gz.
- [For decompression operations]
-
The system assumes that a file that has the extension .gz or .tgz, and has a suffix attached, is a compressed file.
The specifiable length of the suffix ranges from 1 to 30 bytes. Multibyte characters cannot be used for a suffix. For details about behavior when a suffix is specified, see Handling of the extensions of compressed files.
-q
- --quiet
-
Suppresses message output.
However, the following messages are outside the scope of suppression:
-
Error messages for analyzing options
-
For compression operations, messages that confirm whether you want to overwrite an existing file that has the same name as the compressed file
-
For decompression operations, messages that confirm whether you want to overwrite an existing file that has the same name as the decompressed file.
[For display operations]
Does not display the following information:
-
Header line
-
Total information of multiple compressed files
If the -v option is specified after this option, the specification for this option is canceled.
-
-v
- --verbose
-
Displays the following information:
-
For compression operations, decompression operations, and verification operations, the content indicated in Table 8-12 Detailed information output for compression operations, decompression operations, and verification operations are output to the standard error output as the detailed information of the operation result.
-
In a display operation, detailed information such as the compression method is also displayed in the compressed file information. For details about the content to be displayed, see Displaying compressed file information.
-
When files in a directory are searched with the -r option specified, the following message is output to the standard error output, for files that are outside the scope of the operation.
[For compression operations]
For compressed files: gzip: file-name already has suffix suffix -- unchanged is output.
[For decompression operations, display operations, and verification operations]
For files other than compressed files: gzip: file-name: Unknown suffix: ignored is output.
If the -q option is specified after this option, the specification for this option is canceled.
-
Operation type |
Content# and description of the detailed information (top line: content, bottom line: description) |
---|---|
Compress |
[name-of-the-file-to-be-compressed: ]compression-ratio%[ -- replaced with compressed-file-name] |
Outputs the name of the file to be compressed, the compression ratio, and the name of the compressed file. When the -c option is specified, the compressed file name is not output. When entered from the standard input, the name of the file to be compressed and the compressed file name are not output. |
|
Decompress |
compressed-file-name: compression-ratio%[ -- replaced with file-name-after-decompression] |
Outputs the name of the compressed file, the compression ratio, and the name of the file after decompression. When the -c option is specified, the name of the file after decompression is not output. When entered from the standard input, no detailed information is output. |
|
Verify |
[compressed-file-name: ] OK |
Outputs OK, which indicates that there are no problems in integrity between the name of the compressed file and the compressed file data. When entered from the standard input, the name of the compressed file is not output. |
- #
-
-
Displays name-of-the-file-to-be-compressed: in name-of-the-file-to-be-compressed:tab-character.
-
Displays compressed-file-name: in compressed-file-name:tab-character.
-
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination. |
1 |
Termination with an error. The results of compression operations and decompression operations are as follows:
|
2 |
Termination with an error. The results of compression operations and decompression operations are as follows:
Note that when an operation is performed on multiple files and errors for both the return codes 1 and 2 occur, 1 is returned as the return code. |
3 |
An invalid option has been specified. |
The return code is 1 when the following message is output:
-
gzip: file-name already has suffix suffix -- unchanged
-
gzip: file-name: Unknown suffix: ignored
Handling of the most recent access date and time or the most recent modification date and time for a file
In compression operations and decompression operations, the most recent access date and time or the most recent modification date and time for a file is used as follows:
-
For compression operations
In compression operations, usually the most recent access date and time and the most recent modification date and time of the file to be compressed are inherited by the compressed file. In addition, the most recent modification date and time of the file to be compressed is stored in the compressed file.
Depending on the input source and option settings of the file to be compressed, the most recent access date and time and the most recent modification date and time for the file are handled as follows:
Table 8‒13: Handling of the most recent access date and time or the most recent modification date and time in compression operations Input source of the file to be compressed
Output destination of the compression result
Option#1
Compression result
The most recent access date and time or the most recent modification date and time of the compressed file
The most recent modification date and time stored in the compressed file#2
File
Compressed file
-N
The most recent access date and time or the most recent modification date and time of the file to be compressed
The most recent modification date and time of the file to be compressed
-n
The most recent access date and time or the most recent modification date and time of the file to be compressed
The most recent modification date and time are not stored in the compressed file
Standard output
(When the -c option is specified.)
-N
Not inherited#3
The most recent modification date and time of the file to be compressed#2
-n
Not inherited#3
The most recent modification date and time are not stored in the compressed file#2
Standard input
Standard output
-N
Not inherited#3
Date and time of command execution#2
-n
Not inherited#3
The most recent modification date and time are not stored in the compressed file#2
- #1
-
If neither the -N nor -n option is not specified, the -N option is assumed.
- #2
-
When the output destination of the compression result is standard output, indicates the most recent modification date and time within the compressed file data output to the standard output.
- #3
-
Handling of the most recent access date and time and the most recent modification date and time follows the specification (redirect or pipe) of the output destination of the compression result.
Note that if you fail to set the most recent access date and time and the most recent modification date and time for the file, an error occurs, but the compressed file is created and the files to be compressed are deleted.
-
For decompression operations
In decompression operations, usually the most recent access date and time and the most recent modification date and time of the compressed file are inherited by the decompressed file.
Depending on the option settings and whether the most recent modification date and time is stored in the compressed file, handling of the most recent modification date and time for the file works as follows:
Table 8‒14: Handling of the most recent access date and time or the most recent modification date and time in decompression operations Option#
Storage of the most recent modification date and time in the compressed file
Decompression result
The most recent access date and time set for the decompressed file
The most recent modification date and time set for the decompressed file
-N
Stored
The most recent access date and time of the compressed file
The most recent modification date and time stored in the compressed file
Not stored
The most recent access date and time of the compressed file
The most recent modification date and time of the compressed file
-n
Stored
The most recent access date and time of the compressed file
The most recent modification date and time of the compressed file
Not stored
The most recent access date and time of the compressed file
The most recent modification date and time of the compressed file
- #
-
If neither the -N nor -n option is specified, the -n option is assumed.
In decompression operations such as those below, the most recent modification date and time stored in the compressed file are not used.
-
When the compressed file is entered from the standard input and the decompression result is output to the standard output.
-
When the decompression result is output to the standard output by specifying the -c option.
Handling of the most recent access date and time and the most recent modification date and time in this decompression operation follows the specification (redirect or pipe) of the output destination of the decompression result.
Note that if you fail to set the most recent access date and time and the most recent modification date and time for the file, an error occurs, but the decompressed file is created and the compressed file is deleted.
Handling of user IDs, group IDs, and permissions in compression and decompression operations
In UNIX, user IDs, group IDs, and permissions of files are handled as follows:
- [For compression operations]
-
User IDs, group IDs, and permissions of files to be compressed are inherited by the compressed files.
- [For decompression operations]
-
User IDs, group IDs, and permissions of compressed file are inherited by the decompressed files.
In addition, user IDs, group IDs, and permissions are handled as follows:
-
Sticky bits, setuid bits, and setgid bits are not inherited.
-
An error does not occur even if inheriting of user IDs and group IDs fails. If inheriting fails, the user ID and group ID of the user executing the command is set.
-
An error occurs when inheriting of the permission fails. However, compressed files or decompressed files are created. In addition, the files to be compressed or the compressed files are deleted.
-
When the file is entered from the standard input, or when the result of compression or decompression is output to the standard output by specifying the -c option, the user ID, group ID, and permissions are not inherited. Handling of user IDs, group IDs, and permissions follows the specification (redirect or pipe) of the output destination of the standard output.
In Windows, the file owner, ACL, and file attributes are not inherited.
Handling of the extensions of compressed files
This section explains the handling of the extensions of compressed files. Note that to enter the files to be compressed or the compressed files from the standard input, there is no need to be aware of the file extension.
-
Handling of files that are compressed by using compression operations
In a compression operation, when an extension .gz or .tgz, or the suffix specified in the -S option is attached to the name of the file to be compressed, the file is assumed to have been compressed, and compression is not performed. In addition, for files that are already compressed, the message gzip: file-name already has suffix suffix -- unchanged is output.
If the -r option is specified, compression is not performed on already-compressed files found in the directory. Furthermore, the message gzip: file-name already has suffix suffix -- unchanged is not output. Note that the message is output when the -v option is specified.
When the -c option is specified, compressed files are also compressed.
-
Extensions of compressed files that are targets for decompression, display, or verification
In decompression operations, verification operations, and display operations, extensions for compressed files are handled as follows:
-
When specifying compressed file names in the arguments
[For decompression operations]
When the extension .gz or .tgz, or the suffix specified in the -S option is attached to the compressed file name, the file is assumed to be a compressed file and decompression is performed. For other files, decompression is not performed. In addition, for the specified file, the message gzip: file-name: Unknown suffix: ignored is output.
[For display operations and verification operations]
The operation is performed even when the extension .gz or .tgz, or the suffix specified in the -S option is not attached to the compressed file name.
-
When searching the directory by specifying the -r option
The operation is performed on files that exist in the directory and have the extension .gz or .tgz, or the suffix specified in the -S option. The operation is not performed on files that do not have the extension .gz or .tgz, or the suffix specified in the -S option. Furthermore, the message gzip: file-name: Unknown suffix: ignored is not output. Note that the message is output when the -v option is specified.
In the decompression operations, note that when the -c option is specified, decompression is attempted even when the file name does not have the extension .gz or .tgz, or the suffix specified in the -S option.
-
-
Handling of character types for extensions
Checking of the extensions of compressed files is not case-sensitive for the extensions .gz and .tgz, and the suffix specified in the -S option. For example, a file is assumed to be compressed even if its file name is file.GZ.
-
Supplement of the extensions of compressed file names
In decompression operations, display operations, and verification operations, the compressed file names can be specified in the arguments in the following ways:
-
When the extension of the compressed file is .gz, the description for .gz can be omitted.
-
When the compressed file name ends with the suffix specified in the -S option, the description for the suffix can be omitted.
The .gz extension and the suffix specified in the -S option can be supplemented by the command.
However, for compressed files with the extension .tgz, the description for .tgz cannot be omitted.
The following shows an example of supplementing the extension .gz to the compressed file specified in the arguments:
$ ls file1.txt.gz $ gzip -d file1.txt $ ls file1.txt
-
Note that when more than one file is stored in the directory that is being operated, the system works as follows:
-
When the only difference between two compressed files is the .gz extension and the suffix specified in the -S option, the compressed file that has the suffix specified in the -S option becomes the target of the operation.
-
When one of the files has the extension .gz or the suffix specified in the -S option and the other file does not, the latter file becomes the target of the operation.
When an extension is supplemented, handling of the extension .gz and the uppercase or lowercase characters specified in the suffix for the -S option depends on the OS.
- [In UNIX]
-
Supplementation is case-sensitive.
-
The extension .gz
Supplementation can be performed on compressed files that have the lowercase extension .gz.
Supplementation cannot be performed on compressed files that have the extension .GZ, .gZ, or .Gz.
-
The suffix specified in the -S option
Supplementation can be performed on compressed files that have the suffix specified in the -S option.
Supplementation cannot be performed on compressed files whose suffix has a different configuration of uppercase and lowercase letters from the specified suffix.
-
- [In Windows]
-
Supplementation is not case-sensitive.
-
The extension .gz
Supplementation can be performed on compressed files that have the lowercase extension .gz, or any of the extensions .GZ, .gZ, and .Gz.
-
The suffix specified in the -S option
Supplementation can be performed on compressed files that have the suffix specified in the -S option.
Supplementation can also be performed on compressed files whose suffix has a different configuration of uppercase and lowercase letters from the specified suffix.
-
Displaying compressed file information
When the information of a compressed file is displayed, first the item name is displayed in the header line, and then the compressed file information is displayed in the next line. Display of the header line can be suppressed by using the -q option.
-
Items to be displayed
Displays the following items (rows): Items method, crc, date, and time are displayed when the -v option is specified.
Table 8‒15: Items (rows) displayed for compressed file information Item name
Content
method
Indicates the compression method. Displays the following values:
defla: The compressed data is compressed by using the DEFLATE compression method.
crc
Indicates the value of the cyclical redundancy check (CRC) of the file data before compression. The value is displayed in 8-digit hexadecimal numbers.
The integrity of the compressed file data is verified by using this value.
When a file of size 0 is compressed, 00000000 is displayed.
When a compressed file is entered from the standard input, ffffffff is displayed#1.
date
Indicates the month and day of the most recent modification date and time of the file. This month and day is to be set for the file after decompression. The year is not displayed.
The content to be displayed differs depending on the input source and the specified options of the compressed file.
For details, see Table 8-16 Date and time display.
time
Indicates the hour and minute of the most recent modification date and time of the file. This hour and minute is to be set for the file after decompression. Seconds are not displayed.
The content to be displayed differs depending on the input source and the specified options of the compressed file.
For details, see Table 8-16 Date and time display.
compressed
Indicates the size of the compressed file.
When a compressed file is entered from the standard input, -1 is displayed#1.
uncompressed
Indicates the file size before compression.
When a compressed file is entered from the standard input, -1 is displayed#1.
When the file size before compression is 4 GB or greater, the value might not be displayed correctly#2.
ratio
Indicates the compression ratio (%). Displays the value up to the first decimal place.
The compression ratio is calculated based on the file size before compression and the length of the compressed data in the compressed file. Note that the length of the compressed data is different from the size of the compressed file.
When -1 is displayed in the compressed or uncompressed items, 0.0% is displayed.
When compressing a small file or a file whose compression effect is small, the compression ratio might be negative.
uncompressed_name
Indicates the name of the file after decompression. When the compressed file name is specified from the directory path name, a path name consisting of the directory part of the path name and the file name after decompression is displayed. When the compressed file is entered from the standard input, stdout is displayed.
The content to be displayed differs depending on the input source and the specified options of the compressed file.
For details, see Table 8-17 Display of the uncompressed_name item.
- #1
-
If you specify the -t option, you can display the same content as if you had entered from the compressed file, even when entering from the standard input. However, depending on the size of the compressed file, it might take some time to display the information.
- #2
-
To display files that are 4 GB or greater, use the -t option. However, it might take some time to display the information.
Table 8‒16: Date and time display Input source of the compressed file
Storage of the most recent modification date and time in the compressed file#1
Options to be specified#2
Month, day, hour, and minute of the most recent modification date and time to be displayed
File
Stored
-N
The most recent modification date and time stored in the compressed file (the most recent modification date and time of the files before compression)
-n
The most recent modification date and time of the compressed file itself
Not stored
-N
The most recent modification date and time of the compressed file itself
-n
The most recent modification date and time of the compressed file itself
Standard input
Stored
-N
The most recent modification date and time stored in the compressed file (the most recent modification date and time of the files before compression)
-n
Date and time of command execution
Not stored
-N
Date and time of command execution
-n
Date and time of command execution
- #1
-
Whether the most recent modification date and time will be stored in the compressed file is determined by the input method or the option specifications of the file to be compressed by the compression operation. For details about using the most recent modification date and time in compression operations, see Handling of the most recent access date and time or the most recent modification date and time for a file.
- #2
-
If neither the -N nor -n option is specified, the -n option is assumed.
Table 8‒17: Display of the uncompressed_name item Input source of the compressed file
Storage of the file name in the compressed file#1
Options to be specified#2
File name after decompression
File
Stored
-N
The name of the file stored in the compressed file (name of the files before compression)
-n
The name of the file generated from the compressed file name (such as by removing the extension of the compressed file)
Not stored
-N
The name of the file generated from the compressed file name (such as by removing the extension of the compressed file)
-n
The name of the file generated from the compressed file name (such as by removing the extension of the compressed file)
Standard input
Stored
-N
The name of the file stored in the compressed file (name of the files before compression)
-n
stdout
Not stored
-N
stdout
-n
stdout
- #1
-
Whether the file name will be stored in the compressed file is determined by the input method or the specification of the -N or -n option for the file that is to be compressed by the compression operation. For details about the file name to be stored in the compressed file, see the description of the arguments for the -N and -n options.
- #2
-
If neither the -N nor -n option is specified, the -n option is assumed.
-
Displaying the total information of multiple compressed files
When specifying multiple compressed files in an argument or when targeting all compressed files in a directory by using the -r option, the compressed file information for each file is displayed first, and then the total information of multiple compressed files is displayed in the last line. The displayed content is shown in Table 8-18 Display of the total information of multiple compressed files.
Displaying this information can be suppressed by using the -q option. In addition, when input from the standard input is included (where -1 is displayed in compressed or uncompressed) in the files to be displayed, this information is not displayed.
Table 8‒18: Display of the total information of multiple compressed files Item name
Content
compressed
Indicates the total size of the compressed files.
uncompressed
Indicates the total file size before compression.
ratio
Indicates the compression ratio calculated based on the total compressed file size and the total length of the compressed file data.
uncompressed_name
(totals)
Handling of link files
This command uses link files (symbolic links or hard links) as follows:
- [For compression operations and decompression operations]
-
In compression operations and decompression operations, link files for files to be compressed or for compressed files cannot be operated. However, you can operate link files by specifying the -f option. The behavior when link files are operated while the -f option is specified is as follows:
Operation type
Behavior when link files are operated
Compress
-
Compresses the file data of the link destination.
-
When generating the compressed file name from a file name, generates from the link file name.
-
Stores the link file name as the file name to be stored in the compressed file.
-
Deletes the link files after compression.
Decompress
-
Decompresses the compressed data of the file in the link destination.
-
When generating the decompressed file name from a file name, uses the link file name.
-
Deletes the link files after decompression.
Furthermore, specify the -k option if you do not want to delete the link file after compression or decompression.
You can operate link files by specifying the -c option.
Symbolic links to a directory can be used to search within a directory by specifying the -r option. However, the -f option must be specified at the same time as the -r option. When the -f option is specified, the destinations of symbolic links to a directory are followed. In addition, when a directory is searched recursively, the destinations of symbolic links to encountered directories are followed. Note that when the -c option is specified, the destinations of symbolic links to directories are followed.
-
- [For display operations and verification operations]
-
Link files can be used in display operations and verification operations. When a link file is specified for the compressed file, the link destination is followed and the compressed file at the link destination is referenced for display or verification. However, when a file name after decompression is displayed in a display operation, the name generated from the link file name is displayed instead of the compressed file name at the link destination.
When a search is performed within a directory by specifying the -r option, symbolic links to directories are followed to their destination. In addition, when a directory is searched recursively, the destinations of symbolic links to encountered directories are followed.
Notes
-
This command supports operation only on compressed files that were created by the command itself. The following operations might not be performed correctly:
-
Operations on compressed files in gzip format that were created by other programs (such as the gzip command provided by the OS) by using the gzip command provided by JP1/Advanced Shell.
-
Operations on compressed files created by using the gzip command provided by JP1/Advanced Shell by using a program that can operate compressed files in gzip format (such as the gzip command provided by the OS).
-
-
When you compress a small file or a file whose compression effect is small, the file might sometimes be larger after compression than before compression.
-
When you perform a decompression operation or display operation by specifying the -N option, if any of the conditions below apply to the file name stored in the compressed file, and when the OS or encoding is different from that used at compression, decompression or display might not be performed correctly.
-
When the file name contains encoding-dependent characters such as multibyte characters.
-
When the file name contains characters that can only be used in certain OSs (e.g. using the character \ in a file name in UNIX).
-
-
When the path name, or file name, of the file to be compressed is longer than the following value, creation of the compressed file fails. In such cases, use the -o or -c option to create the compressed file.
-
maximum-path-length-defined-by-OS -length-of-compressed-file-extension
-
maximum-file-name-length-defined-by-OS -length-of-compressed-file-extension
-
-
When any of the following conditions is met, and when a decompression operation is performed by specifying the -N option, the creation of files after decompression fails:
-
The name of the file stored in the compressed file exceeds the maximum file name length defined by the OS.
-
The path name that was generated based on the name of the file stored in the compressed file exceeds the maximum path length defined by the OS.
-
-
The range of dates and times that can be stored as the most recent modification date and time in the compressed file is from 00:00:01 on January 1, 1970 UTC to 03:14:07 on January 19, 2038 UTC. The date and time is not stored if it is outside this range.
-
When command execution is canceled during a compression operation, a partially compressed file might remain.
-
When command execution is canceled during a decompression operation, a partially decompressed file might remain.
-
If you do not have the delete permission for the files to be compressed, deletion of the files to be compressed by the compression operation will fail. The compressed files are created, even if deletion of the files to be compressed fails.
-
If you do not have the delete permission for the compressed file, deletion of the compressed file by the decompression operation will fail. The decompressed files are created, even if deletion of the compressed file fails.
-
When a compressed file, or files after decompression, are created by overwriting existing files, the existing files are deleted first. Therefore, if an error occurs during processing, the existing files might already have been deleted.
-
If the file to be operated and the output file are substantially the same (they have the same symbolic link destination or the hard link destination), an error occurs.
-
For compressed files created from multiple files by using the -c option, or compressed files created by linking multiple compressed files by using the cat command, the decompression operation or display operation is performed as follows:
-
One decompressed file is created by outputting the data of multiple files. Decompressed files corresponding to each file before compression are not created.
-
When a file is decompressed by specifying the -N option, the file name of the created decompressed file is taken from the information of the file that was first specified at the time the compressed file was created.
-
In a display operation, the size of the file that was last specified at the time the compressed file was created, is displayed as the file size before compression. In addition, the compression ratio is calculated based on the value derived above. Note that when the -t option is specified, the total size of all files is displayed.
-
-
In Windows, when a short name is specified as the name of the file to be compressed or as the name of the compressed file, the created compressed file or decompressed file also has a short name.
-
In Windows, the file names are not case-sensitive. Therefore, the behavior is as follows:
-
File names with the same spelling as the compressed file or decompressed file but are capitalized differently are assumed to be the same file. For example, if there is a file whose name has the same spelling as the compressed file or the decompressed file to be created, and only the capitalization is different, the command assumes that the same file already exists.
-
When the name of the file to be compressed or the compressed file is specified in the arguments using different capitalization, the created compressed file or decompressed file takes the file name specified in the argument.
-
-
In Windows, when the file to be operated or an existing file to be overwritten is used by different program, deletion of that file might fail.
-
In Windows, if the read-only attribute is set for files to be compressed or to be decompressed, a 1,550-millisecond delay occurs when each of these files is deleted. When specifying multiple files by using a wildcard, or when compressing or decompressing multiple files in a directory by specifying the -r option, remove the read-only attributes first.
Examples
-
Compress the files.
C:\TEMP>%ADSH_OSCMD_DIR%gzip file001.txt C:\TEMP>%ADSH_OSCMD_DIR%ls file001.txt.gz
-
Specify the -k option to compress a file without deleting it.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -k file001.txt C:\TEMP>%ADSH_OSCMD_DIR%ls file001.txt file001.txt.gz
-
Specify the -o option to create a compressed file with a different name from that generated by the command.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -o save_file002.gz file002.txt C:\TEMP>ls save_file002.gz
-
Specify the -c option to compress a file without deleting it.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -c file003.txt > backup_file003.gz C:\TEMP>ls backup_file003.gz file003.txt
-
Specify the -S option to create a compressed file that has an extension other than .gz.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -S ".gzip" file004.txt C:\TEMP>ls file004.txt.gzip
-
Specify the -r option to compress a file in a directory.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -r DIR002 C:\TEMP>ls -R DIR002 DIR003 file001.txt.gz file002.txt.gz file003.txt.gz DIR002\DIR003: file004.txt.gz file005.txt.gz
-
Specify the -v option to output the compression ratio and the compressed file name at compression.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -v file005.txt file005.txt: 26.5% -- replaced with file005.txt.gz
Note that the compression ratio and the compressed file name are output to the standard error output.
-
Decompress the compressed file.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -d file001.txt.gz C:\TEMP>%ADSH_OSCMD_DIR%ls file001.txt
-
Specify the -o option to create a decompressed file with a different name from that generated by the command.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -d -o FILE002.txt save_file002.gz C:\TEMP>ls FILE002.txt
-
Specify the -c option to decompress the file without deleting the compressed file.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -d -c backup_file003.gz >file003.txt C:\TEMP>ls backup_file003.gz file003.txt
-
Specify the -N option to decompress a file by using the file name before compression.
C:\DIR001>%ADSH_OSCMD_DIR%gzip -d -N backup_file003.gz C:\DIR001>ls file003.txt
-
Specify the -S option to decompress a compressed file that has an extension other than .gz.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -d -S ".gzip" file004.txt.gzip C:\TEMP>ls file004.txt
-
Specify the -r option to decompress a compressed file in a directory.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -d -r DIR002 C:\TEMP>ls -R DIR002 DIR003 file001.txt file002.txt file003.txt DIR002\DIR003: file004.txt file005.txt
-
Specify the -v option to output the decompression ratio and the decompressed file name at decompression.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -d -v file005.txt.gz file005.txt.gz: 26.5% -- replaced with file005.txt
Note that the decompression ratio and the decompressed file name are output to the standard error output.
-
Displays information about the compressed file.
C:\TEMP>gzip -l file001.txt.gz compressed uncompressed ratio uncompressed_name 25025357 34040107 26.5% file001.txt
-
Specify the -v option to display detailed information about a compressed file.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -l -v file001.txt.gz method crc date time compressed uncompressed ratio uncompressed_name defla fe65cbfa Dec 23 16:52 25025357 34040107 26.5% file001.txt
-
Displays information about multiple compressed files.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -l -v file001.txt.gz file002.txt.gz file003.txt.gz file004.txt.gz file005.txt.gz method crc date time compressed uncompressed ratio uncompressed_name defla 5d262330 Dec 23 17:12 16142040 17838735 9.5% file001.txt defla 0e523a79 Dec 23 17:12 18824484 20542848 8.4% file002.txt defla 1cb8a527 Dec 23 17:12 12476069 17673807 29.4% file003.txt defla b167ed5d Dec 23 17:12 19489411 22390086 13.0% file004.txt defla 9b4d3435 Dec 23 17:12 19631128 22513931 12.8% file005.txt 86563132 100959407 14.3% (totals)
-
Verifies the integrity of a compressed file. In addition, specify the -v option to output the verified result.
C:\TEMP>gzip -t -v file001.txt.gz file001.txt.gz: OK
Note that the verified result is output to the standard error output.
-
Compress the archive result of the tar command.
C:\TEMP>%ADSH_OSCMD_DIR%tar -cvf - DIR002 | %ADSH_OSCMD_DIR%gzip > DIR002.tar.gz DIR002 DIR002/DIR003 DIR002/DIR003/file004.txt DIR002/DIR003/file005.txt DIR002/file001.txt DIR002/file002.txt DIR002/file003.txt
-
Pass the result of decompressing the compressed archive to the tar command and expand the archive.
C:\TEMP>%ADSH_OSCMD_DIR%gzip -d -c DIR002.tar.gz | %ADSH_OSCMD_DIR%tar -xvf - DIR002 DIR002\DIR003 DIR002\DIR003\file004.txt DIR002\DIR003\file005.txt DIR002\file001.txt DIR002\file002.txt DIR002\file003.txt