Home >Operation and Maintenance >Linux Operation and Maintenance >gunzip and unzip decompress files to the specified directory
Commonly used compression commands in Linux include gzip and zip. The endings of the two compressed packages are different: the zip compressed file is *.zip, and the gzip compressed file is *.gz
Correspondingly The decompression commands are gunzip and unzip
gzip command:
# gzip test.txt
It will compress the file into the file test.txt.gz, and the original file will be gone. The same goes for compression
# gunzip test.txt.gz
It will decompress the file into the file test.txt, and the original file will be gone. In order to retain the original file, we can add - c option and use linux redirection
# gzip -c test.txt > /root/test.gz
Not only can the original files be retained, but the compressed package can be placed anywhere directory, decompression is the same
# gunzip -c /root/test.gz > ./test.txt
zip command:
# zip test.zip test.txt
It will compress the test.txt file into test.zip. Of course, you can also specify the directory of the compressed package, such as /root/test.zip
# unzip test.zip
It The file will be decompressed to the current directory by default. If you want to decompress to the specified directory, you can add the -d option
# unzip test.zip -d /root/
The above is the detailed content of gunzip and unzip decompress files to the specified directory. For more information, please follow other related articles on the PHP Chinese website!