1. tar打包命令
- tar cf target.tar [file1] [file2] ... : 将多个文件打包成target.tar(文件名可修改), 文件也可以是目录, v参数表示列出所有文件。
➜ linux_commands tar cf hello.tar hello*
➜ linux_commands ls hello*
hello.tar hello.txt hello_sorted.txt
➜ linux_commands rm hello.tar
➜ linux_commands tar cvf hello.tar hello*
a hello.txt
a hello_sorted.txt
➜ linux_commands tar cvf temp.tar temp hello.txt
a temp
a temp/bb
a temp/three
a temp/input.txt
a temp/hello.tar.xz
a temp/two
a temp/aa
a temp/hello.tar.gz
a temp/cc
a temp/hello_sorted.txt
a temp/hello.txt
a temp/aa/hello_sorted.txt
a temp/aa/hello.txt
a hello.txt
- tar czf target.tar.gz [file1] [file2] ... : 将多个文件压缩成target.tar.gz(文件名可修改,gz表示用gzip压缩)
➜ linux_commands tar czf hello.tar.gz hello.txt hello_sorted.txt
➜ linux_commands ls hello*
hello.tar.gz hello.txt hello_sorted.txt
- tar tvf source.tar: 列出tar格式打包文件的内容,t参数表示列出打包文件内容
➜ linux_commands tar tvf hello.tar
-rw-r--r-- 0 qiushye staff 92 May 19 12:30 hello.txt
-rw-r--r-- 0 qiushye staff 60 May 15 12:16 hello_sorted.txt
- tar xf source.tar[.gz|.bz2|.xz] -C [path]: 将打包文件提取到当前目录,中括号内的表示其他格式文件, -C 表示提取到目标路径
➜ temp ls hello*
hello.tar.gz
➜ temp tar xf hello.tar.gz
➜ temp ls hello*
hello.tar.gz hello.txt hello_sorted.txt
➜ temp tar xf hello.tar.gz -C aa
➜ temp ls aa
hello.txt hello_sorted.txt
2. gzip 压缩和解压命令
- gzip [file]: 压缩文件[file],并以压缩文件[file.gz]替代原文件
- gzip -d [file.gz]: 解压[file.gz],并以原文件代替压缩文件
➜ linux_commands gzip hello.txt
➜ linux_commands ls hello.txt*
hello.txt.gz
➜ linux_commands gzip -d hello.txt.gz
➜ linux_commands ls hello.txt*
hello.txt
- gzip -c [file] > [file1.gz]: 压缩文件[file],并将压缩名设置为file1.gz,解压操作也可以用-c参数
➜ linux_commands gzip -c hello.txt > hello_1.gz
➜ linux_commands ls hello_1.gz
hello_1.gz
- gzip -3 [file]: 指定压缩等级,1表示最快(最差),9表示最慢(最好),默认等级为6
➜ linux_commands gzip -5 hello.txt
➜ linux_commands ls -l hello.txt.gz
-rw-r--r-- 1 qiushye staff 81 May 19 12:30 hello.txt.gz
- gzip -lv [file.gz]: 展示压缩文件内的列表详情,包括压缩方法,时间,压缩率等
➜ linux_commands gzip -lv hello.txt.gz
method crc date time compressed uncompressed ratio uncompressed_name
defla 50b8a0b9 May 19 12:30 81 92 13.0% hello.txt
3. gunzip从gz压缩包提取文件
- gunzip [file.tar.gz]: 从压缩包[file.tar.gz]中提取文件,若有原文件则替换
➜ linux_commands tar czf combine.tar.gz hello.txt test.txt
➜ linux_commands tar tvf combine.tar.gz
-rw-r--r-- 0 qiushye staff 92 May 19 12:30 hello.txt
-rw-r--r-- 0 qiushye staff 28 May 27 12:36 test.txt
➜ linux_commands gunzip combine.tar.gz
➜ linux_commands ls combine*
combine.tar
- gunzip -c [file.tar.gz] > [target.tar]: 从压缩包[file.tar.gz]中提取为文件[target.tar]
➜ linux_commands gunzip -c combine.tar.gz > ttt1.tar
➜ linux_commands ls ttt*
ttt1.tar
- gunzip -l [file.gz]:展示压缩包的内容
➜ linux_commands gunzip -l hello.txt.gz
compressed uncompressed ratio uncompressed_name
81 92 13.0% hello.txt
4. bzip2块排序压缩
- bzip2 [file]: 压缩文件[file],以bz2为压缩后缀, 加-1...到-9分别表示块大小从100k,200k到900k
➜ linux_commands bzip2 test.txt
➜ linux_commands ls test.txt*
test.txt.bz2
➜ linux_commands bzip2 -3 regex.txt
➜ linux_commands
- bzip2 -d [file.bz2]: 解压压缩文件, -f表示强制覆盖输出文件
➜ linux_commands bzip2 -d test.txt.bz2
➜ linux_commands ls test.txt*
test.txt
➜ linux_commands bzip2 test.txt
➜ linux_commands echo "aa" > test.txt
➜ linux_commands ls test.txt*
test.txt test.txt.bz2
➜ linux_commands bzip2 -d test.txt.bz2
bzip2: Output file test.txt already exists.
➜ linux_commands bzip2 -df test.txt.bz2
➜ linux_commands
- bzip2 -dc [file.bz2]: 解压压缩文件到标准输出, -c表示标准输出
➜ linux_commands bzip2 -dc test.txt.bz2
yes,no
white,black
boy,girl
➜ linux_commands ls test.txt*
test.txt.bz2