Linux常用命令(压缩命令)
来源:互联网 发布:唐筛标准年龄风险数据 编辑:程序博客网 时间:2024/05/24 08:33
一、常用压缩格式
- 常用压缩格式有:.zip .gz .bz2
- 常用压缩格式: .tar.gz .tar.bz2
二、按压缩格式来认识压缩命令
2.1 .zip格式
压缩文件命令:
zip 压缩文件名 源文件
压缩目录命令:
zip -r 压缩文件名 源目录
2.2 问题一
zip: command not found
因为没有安装zip,所以需要下载并安装zip
yum install zip
2.3 .zip格式解压缩
unzip [压缩文件]
解压缩.zip文件
举例:
[root@localhost zixuan]# ls -lh总用量 16Kdrwxr-xr-x. 2 root root 4.0K 5月 22 10:32 laoshi-rw-r--r--. 1 root root 612 5月 20 17:00 laoshi.zipdrwxr-xr-x. 2 root root 4.0K 5月 18 16:09 learndrwxr-xr-x. 2 root root 4.0K 5月 17 11:41 zm[root@localhost zixuan]# rm -rf laoshi[root@localhost zixuan]# lslaoshi.zip learn zm[root@localhost zixuan]# unzip laoshi.zipArchive: laoshi.zip creating: laoshi/ extracting: laoshi/one extracting: laoshi/three extracting: laoshi/two [root@localhost zixuan]# ls -lh总用量 16Kdrwxr-xr-x. 2 root root 4.0K 5月 20 16:59 laoshi-rw-r--r--. 1 root root 612 5月 20 17:00 laoshi.zipdrwxr-xr-x. 2 root root 4.0K 5月 18 16:09 learndrwxr-xr-x. 2 root root 4.0K 5月 17 11:41 zm
2.4 .gz格式压缩
- 压缩为.gz格式的压缩文件,与源文件名一样,但是源文件会消失;
.gzip [源文件]
其中one,two,three都是文件,举例:
[root@localhost laoshi]# lsone three two[root@localhost laoshi]# gzip one[root@localhost laoshi]# lsone.gz three two
- 压缩为.gz格式的压缩文件,并且保留源文件
gzip -c laoshi > laoshi.gz
举例:
[root@localhost laoshi]# lsone.gz three two[root@localhost laoshi]# gzip -c two > two.gz[root@localhost laoshi]# lsone.gz three two two.gz
- 压缩目录下所有的子文件,但是不能压缩目录,这样很不方便。
gzip -r [目录]
举例:
gzip -r laoshi ,会压缩laoshi目录下面的所有子文件
[root@localhost zixuan]# ls laoshione.gz three two two.gz[root@localhost zixuan]# gzip -r laoshigzip: laoshi/two.gz already exists; do you wish to overwrite (y or n)? y[root@localhost zixuan]# ls laoshi learn zm[root@localhost zixuan]# ls laoshione.gz three.gz two.gz
2.5 .gz格式解压缩
解压缩文件
gzip -d [压缩文件]
gunzip [压缩文件]解压缩目录,即解压缩目录下的所有.gz压缩文件
gunzip -r [目录文件]
举例:
[root@localhost zixuan]# cd zm[root@localhost zm]# gunzip abc.gz[root@localhost zm]# ls abc first second[root@localhost zm]# cd ..[root@localhost zixuan]# gunzip laoshigzip: laoshi is a directory -- ignored[root@localhost zixuan]# gunzip -r laoshi[root@localhost zixuan]# ls -l laoshi总用量 0-rw-r--r--. 1 root root 0 5月 20 16:59 one-rw-r--r--. 1 root root 0 5月 20 16:59 three-rw-r--r--. 1 root root 0 5月 20 16:59 two
2.6 .bz2格式压缩
bzip2命令还能压缩目录,只能压缩文件
1、压缩为.bz2格式,并且不保留源文件
bzip [源文件]
2、压缩之后保留源文件
bzip2 -k [源文件]
2.7 .bz2格式解压缩
- 解压缩文件,-k保留压缩文件
bzip2 -d [压缩文件]
bunzip2 [压缩文件]
举例:
[root@localhost zixuan]# ls laoshione three two[root@localhost zixuan]# cd laoshi[root@localhost laoshi]# bzip2 one[root@localhost laoshi]# lsone.bz2 three two[root@localhost laoshi]# bzip2 -k two[root@localhost laoshi]# lsone.bz2 three two two.bz2[root@localhost laoshi]# bzip2 -dk one.bz2[root@localhost laoshi]# lsone one.bz2 three two two.bz2[root@localhost laoshi]# rm tworm:是否删除普通空文件 "two"?y[root@localhost laoshi]# lsone one.bz2 three two.bz2[root@localhost laoshi]# bunzip2 two.bz2[root@localhost laoshi]# lsone one.bz2 three two
2.8 .tar.gz格式与.tar.bz2格式
前面提到的命令gzip与bzip2只能对文件或者子文件进行单独压缩,并不能对整个目录进行压缩,不能打包成一个压缩文件。这样对压缩工作来说,很不方便,那么有没有可以解决这个问题的命令呢?答案当然是有的。在这之前我们先来学习一个打包命令tar:
1、打包命令tar
这种将多个文件或目录打包成一个大文件的命令功能,我们称呼它为“打包命令”。
tar -cvf [打包文件名] [源文件]
tar命令中的选项有:
2、解打包命令
tar -xvf 打包文件名
3、.tar.gz压缩格式
其实.tar.gz格式是先打包为.tar格式,再压缩为.gz格式
tar -zcvf 压缩包名.tar.gz 源文件
将源文件压缩成.tar.gz格式的文件tar -zxvf 压缩包名.tar.gz
将压缩包名.tar.gz的文件解压
4、.tar.bz2压缩格式
其实.tar.bz2格式是先打包为.tar格式,再压缩为.bz2格式
tar -jcvf 压缩包名.tar.bz2 源文件
将源文件压缩成.tar.bz2格式的文件tar -jxvf 压缩包名.tar.bz2
将压缩包名.tar.bz2的文件解压
5、综合举例
[root@localhost zixuan]# ls laoshione three two[root@localhost zixuan]# tar -cvf laoshi.tar laoshilaoshi/laoshi/onelaoshi/threelaoshi/two[root@localhost zixuan]# lslaoshi laoshi.tar learn zm[root@localhost zixuan]# tar -tvf laoshi.tardrwxr-xr-x root/root 0 2017-05-22 11:43 laoshi/-rw-r--r-- root/root 0 2017-05-20 16:59 laoshi/one-rw-r--r-- root/root 0 2017-05-20 16:59 laoshi/three-rw-r--r-- root/root 0 2017-05-20 16:59 laoshi/two[root@localhost zixuan]# lslaoshi laoshi.tar learn zm[root@localhost zixuan]# rm -rf laoshi[root@localhost zixuan]# lslaoshi.tar learn zm[root@localhost zixuan]# tar -xvf laoshi.tarlaoshi/laoshi/onelaoshi/threelaoshi/two[root@localhost zixuan]# lslaoshi laoshi.tar learn zm[root@localhost zixuan]# tar -zcvf laoshi.tar.gz laoshilaoshi/laoshi/onelaoshi/threelaoshi/two[root@localhost zixuan]# lslaoshi laoshi.tar laoshi.tar.gz learn zm[root@localhost zixuan]# tar -jcvf laoshi.tar.bz2 laoshilaoshi/laoshi/onelaoshi/threelaoshi/two[root@localhost zixuan]# lslaoshi laoshi.tar laoshi.tar.bz2 laoshi.tar.gz learn zm[root@localhost zixuan]# tar -jtvf laoshi.tar.bz2drwxr-xr-x root/root 0 2017-05-22 11:43 laoshi/-rw-r--r-- root/root 0 2017-05-20 16:59 laoshi/one-rw-r--r-- root/root 0 2017-05-20 16:59 laoshi/three-rw-r--r-- root/root 0 2017-05-20 16:59 laoshi/two[root@localhost zixuan]# ls laoshione three two
- Linux常用命令(压缩命令)
- Linux常用命令(压缩及解压命令)
- Linux-常用命令(4)压缩解压命令
- Linux曲径通幽:常用命令(压缩解压命令)
- linux常用命令-压缩解压命令
- Linux 常用命令 之 压缩命令
- Linux常用命令-压缩解压命令
- Linux常用命令压缩和解压缩命令1
- Linux常用命令压缩和解压缩命令2
- 笔记:Linux常用命令(四)压缩解压缩命令
- Linux常用命令(10)之压缩与解压缩命令
- Linux常用命令(11)之压缩与解压缩命令
- Linux常用命令详解之压缩解压命令
- Linux常用命令(第二版) --压缩解压缩命令
- Linux常用命令之压缩与解压命令
- linux常用命令之压缩与解压缩命令
- linux常用命令(4、5、6)-帮助命令、用户管理命令、压缩解压命令
- linux常用命令笔记(3压缩解压命令、网络通信命令、Shell应用技巧)
- NSIS制作卸载器时注意事项和如何创建桌面快捷方式
- php JSON数据格式化方法
- Mysql表连接:外连接(左连接右连接)与内连接
- framework 比较靠谱的文章
- Android 下拉刷新上拉加载(解决item未满一页时的显示问题、添加网络错误等提示)
- Linux常用命令(压缩命令)
- scrapy专利爬虫(三)——简单实际操作
- BCGControlBar Debug报错解决
- 关于同步和异步
- Android Kotlin学习之路(一) —— 配置Kotlin
- Android studio 修改程序包名
- Android Studio2.3和Gradle-3.3的升级和配置问题
- iOS 调用系统原生拨打电话
- scrapy专利爬虫(四)——数据处理