2021年11月11日 星期四

Linux 壓縮與打包指令(tar, zip, gz, bz2, xz)

 Linux 壓縮與打包指令有很多種,有些僅有打包功能,有些僅能對單一檔案壓縮,又有些兩者兼具,可以參考以下表格。

以下展示各種指令的範例

# 打包當前資料夾下所有檔案 
$ tar cvf example.tar .
# 解包
$ tar xvf example.tar
# 壓縮 
$ zip example.zip example
# 解壓縮
$ unzip example.zip
# 壓縮 
$ gzip example
# 解壓縮
$ gzip -d example.gz
# 壓縮 
$ bzip2 -z example
# 解壓縮
$ bzip2 -d example.bz2
# 壓縮 
$ xz -z example
# 解壓縮
$ xz -d example.xz
# 打包與壓縮當前資料夾下所有檔案 
$ tar zcvf example.tar.gz .
# 解包
$ tar zxvf example.tar.gz
# 打包與壓縮當前資料夾下所有檔案 
$ tar jcvf example.tar.bz2 .
# 解包
$ tar jxvf example.tar.bz2
# 打包與壓縮當前資料夾下所有檔案 
$ tar Jcvf example.tar.xz .
# 解包
$ tar Jxvf example.tar.xz
    未解壓縮列出內含檔案
    tar -tf filename.tar.gz
    

    screenshot of listing compressed tarball files in the terminal

     

    -t, --list
    List the contents of an archive. Arguments are optional. When given, they specify the names of the members to list.

     

    -f, --file=ARCHIVE Use archive file or device ARCHIVE...


資料來源: https://michael-hsu.medium.com/linux-%E5%A3%93%E7%B8%AE%E8%88%87%E6%89%93%E5%8C%85%E6%8C%87%E4%BB%A4-tar-zip-gz-bz2-xz-77ab131c2cc3

沒有留言: