基础篇

作者: 柒月的天空 | 来源:发表于2018-10-09 21:28 被阅读0次

Linux学习

一、zip压缩工具
二、tar打包
三、打包并压缩

一、zip压缩工具

  • gzip、bzip2、xz都不支持压缩目录,zip支持压缩目录
  • 安装工具可以解压windows下的rar文件
  • 安装zip工具,yum install -y zip
  • 压缩文件:zip 2.txt.zip 2.txt
  • 压缩目录:zip -r 111.zip 3.txt 111 把目录111和文件3.txt同时压缩至111.txt
  • zip压缩的特点是压缩之后不删除原文件
  • zip解压缩命令:unzip,需安装unzip工具:yum install -y unzip
  • unzip支持解压到指定目录下
  • unzip时,压缩前的文件名不能被改动
  • zip压缩后不能查看其内容,但是可以查看文件列表
  • 查看文件列表命令:unzip -l 111.zip
操作
[root@01 d6z]# zip 2.txt.zip 2.txt 
  adding: 2.txt (deflated 75%)
[root@01 d6z]# ls
12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# du -sh 2.txt
8.0M    2.txt
[root@01 d6z]# du -sh 2.txt
2.txt      2.txt.zip  
[root@01 d6z]# du -sh 2.txt.zip 
1.5M    2.txt.zip
[root@01 d6z]# 


[root@01 d6z]# zip -r 111.zip 2.txt 111
  adding: 2.txt (deflated 75%)
  adding: 111/ (stored 0%)
  adding: 111/2.txt (deflated 75%)
[root@01 d6z]# ls
111  111.zip  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# du -sh 111.zip 
2.9M    111.zip
[root@01 d6z]# 



[root@01 d6z]# unzip 111.zip 
Archive:  111.zip
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: 2.txt                   
replace 111/2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: 111/2.txt               
[root@01 d6z]# ls
111  111.zip  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# tree
.
├── 111
│   └── 2.txt
├── 111.zip
├── 12.txt.gz
├── 2.txt
├── 2.txt.zip
├── a.txt
├── a.txt.xz
└── b.txt

1 directory, 8 files
[root@01 d6z]# unzip 111.zip 
Archive:  111.zip
replace 2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: n
replace 111/2.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: 111/2.txt               
[root@01 d6z]# ls
111  111.zip  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# 



[root@01 d6z]# mkdir 12
[root@01 d6z]# unzip 2.txt.zip  -d 12/
Archive:  2.txt.zip
  inflating: 12/2.txt                
[root@01 d6z]# ls
111  111.zip  12  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# tree
.
├── 111
│   └── 2.txt
├── 111.zip
├── 12
│   └── 2.txt
├── 12.txt.gz
├── 2.txt
├── 2.txt.zip
├── a.txt
├── a.txt.xz
└── b.txt

2 directories, 9 files
[root@01 d6z]# 



[root@01 d6z]# unzip -l 111.zip 
Archive:  111.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
  6090777  10-09-2018 08:40   2.txt
        0  10-09-2018 08:44   111/
  6090777  10-09-2018 08:44   111/2.txt
---------                     -------
 12181554                     3 files
[root@01 d6z]# 

二、tar打包

  • 便于大文件传输,节省带宽资源
  • tar -cvf 111.tar 111/ 参数: -c创建,-v可视化,-f文件名
  • tar支持重复打包
  • 解包tar -xvf 111.tar,tar解包后不会提示是否覆盖源文件,直接覆盖
  • tar支持文件和目录同时打包
  • tar -tf 111.tar 参数:-tf查看包
  • tar可以过滤指定的文件或者目录
  • tar -cvf 111.tar --exclude name.sh 111/
  • 参数:--exclude后面跟指定过滤的文件或者目录
操作
[root@01 d6z]# ls
111  111.zip  12  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# tar -cvf  111.tar 111/
111/
111/2.txt
[root@01 d6z]# ls
111  111.tar  111.zip  12  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# 
[root@01 d6z]# tar -cvf  111.tar 111/
111/
111/2.txt
[root@01 d6z]# ls
111  111.tar  111.zip  12  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# 

[root@01 d6z]# tar -tf 111.tar
111/
111/2.txt
[root@01 d6z]# 

[root@01 d6z]# tar -cvf 123.tar --exclude a.txt 111/
111/
111/2.txt
[root@01 d6z]# ls
111  111.tar  111.zip  12  123.tar  12.txt.gz  2.txt  2.txt.zip  a.txt  a.txt.xz  b.txt
[root@01 d6z]# tar -tf 123.tar 
111/
111/2.txt
[root@01 d6z]# 

三、打包并压缩

  • 打包的同压缩文件
  • tar -czvf test.tar.gz liyang/ 参数:z表示压缩类型为gz
  • tar -cjzf test.tar.bz2 liyang/ 参数:j表示压缩类型为bz2
  • tar -cJzf test.tar.bz2 liyang/ 参数:J表示压缩类型为xz
  • 解包把参数c改为x即可
  • 查看包和压缩同样使用-tf参数
  • 利用tar通过网络拷贝数据
  • cd /data // data目录下有我们要拷贝的目标文件目录 test
  • tar cvf - test| ssh 10.0.1.11 "cd /copy1/; tar xvf -"
  • 首先将要拷贝的目录test打包,"-" 代表标准输出,
  • 然后再ssh 到目标主机 10.0.1.11 ,运行相应的命令。
  • 其中tar xvf - 意思是,将前面的标准输出内容作为解包的对象。
  • 目的就是想拷贝的目录先打包,然后将打包好的文件拷贝到目标主机最后在目标主机上解包
  • 此处用一条命令实现了边打包边解包的过程
  • 把打包压缩的文件解压到指定目录下
  • 加参数-C后面跟指定目录即可
  • Linux下不支持解压大于4G的文件解决方法
  • 解压命令:
  • 7z x 123.zip
操作
[root@01 d6z]# tar -czvf 111.tar.gz aaa/
aaa/
[root@01 d6z]# ls
111  111.tar.gz  111.zip  12  123.tar  12.txt.gz  2.txt  2.txt.zip  aaa  a.txt  a.txt.xz  b.txt


[root@01 d6z]# tar -xzvf 33.tar.gz -C /tmp/
test/
[root@01 d6z]# cd ..
[root@01 tmp]# ls
a.txt.bz2  systemd-private-e48e1da9d62f410cb1a1742df18f10e7-chronyd.service-oR4g8U
a.txt.gz   systemd-private-e48e1da9d62f410cb1a1742df18f10e7-vgauthd.service-8YdZ30
a.txt.xz   systemd-private-e48e1da9d62f410cb1a1742df18f10e7-vmtoolsd.service-vCNEnQ
d6z        test
[root@01 tmp]# 

wget -c http://packages.sw.be/p7zip/p7zip-9.13-1.el5.rf.i386.rpm 
wget -c http://packages.sw.be/p7zip/p7zip-plugins-9.13-1.el5.rf.i386.rpm 

rpm -ivh p7zip-9.13-1.el5.rf.i386.rpm 
rpm -ivh p7zip-plugins-9.13-1.el5.rf.i386.rpm 

相关文章

  • 最新web前端相关课程学习链接

    js基础篇 js进阶篇 js高级篇 vue基础篇 vue高级篇 react基础 react高级 Nodejs基础 ...

  • Java工程师成神之路

    基础篇进阶篇高级篇架构篇扩展篇推荐书籍 基础篇 一、基础篇JVM JVM内存结构 堆、栈、方法区、直接内存、堆和栈...

  • iOS 动画基础总结篇

    iOS 动画基础总结篇 iOS 动画基础总结篇

  • axios进阶之路——基础篇

    本课题包含三篇:基础篇;拦截器篇;封装篇。本篇为基础篇,主题为axios基础介绍及安装使用。 一、 关于Axios...

  • 线上思维导图课程总结

    一、学习内容 学习的内容:基础篇、学习篇、运用篇。包括基础篇的:思维导图开启全新思维、开通基础篇学习了思维导图...

  • 一、基础

    基础篇为python基础内容

  • java多线程相关

    (一) 基础篇 01.Java多线程系列--“基础篇”01之 基本概念 02.Java多线程系列--“基础篇”02...

  • Hybrid APP - 混合式开发

    Hybrid APP基础篇(一)->什么是Hybrid App Hybrid APP基础篇(二)->Native、...

  • 基础篇_1.音视频学习框架

    学习整理的相关章节链接:基础篇_1.音视频学习框架基础篇_2. 颜色空间模型 RBG、YUV、HSV基础篇_3.图...

  • 基础篇_8.音频编码MP3\AAC

    学习整理的相关章节链接:基础篇_1.音视频学习框架基础篇_2. 颜色空间模型 RBG、YUV、HSV基础篇_3.图...

网友评论

      本文标题:基础篇

      本文链接:https://www.haomeiwen.com/subject/mbgyaftx.html