2018-08-09直播笔记
上节课
VIM 三种模式 一般 编辑 命令
命令模式
1,$#word1#newword#g 替换
打包 、解压 、压缩
使用压缩工具的好处:
使用压缩文件,不仅可以节省磁盘空间,而且在传输时还能节省网络宽带。
机房宽带的上行和下行都是100M,所以价格昂贵,家用宽带下行是100M,但是上行往往只有10M-20M
常见后缀格式
Linux下最常见的压缩文件是.tar.gz格式,还有.zip,.gz,.bz2,.xz,.tar.bz2,.tar.xz
等。
.gz 表示由gzip压缩工具压缩的文件。
.bz2 表示由bzip2压缩工具压缩的文件。
.tar 表示由tar打包程序打包的文件(tar没有压缩功能,只是把一个目录合并成一个文件)
.tar.gz 先打包,在由gzip压缩
.tar.bz2 先打包,在由bzip2压缩
.tar.xz 先打包,在由xz压缩
查找/etc/下后缀为.conf的文件,并将它的内容追加到文件1.txt中,并且压缩它,然后再解压。
find /etc -name "*.conf" -^Cec cat {} >> 1.txt \;
releasenotes/ requirements.txt.xz requirements.txt.zip
[[email protected] trove]# file requirements.txt.xz
requirements.txt.xz: XZ compressed data
使用压缩文件,不仅可以节省磁盘空间,而且在传输时还能节省网络宽带。
机房宽带的上行和下行都是100M,所以价格昂贵,家用宽带下行是100M,但是上行往往只有10M-20M
- Linux下最常见的压缩文件是.tar.gz格式,还有.zip,.gz,.bz2,.xz,.tar.bz2,.tar.xz
- 等。
- .gz 表示由gzip压缩工具压缩的文件。
- .bz2 表示由bzip2压缩工具压缩的文件。
- .tar 表示由tar打包程序打包的文件(tar没有压缩功能,只是把一个目录合并成一个文件)
- .tar.gz 先打包,在由gzip压缩
- .tar.bz2 先打包,在由bzip2压缩
- .tar.xz 先打包,在由xz压缩
- gzip -# filename //#范围1-9,默认6
- gzip 不能压缩目录
- gzip filename 压缩文件,暂不支持压缩目录,压缩后源文件消失
- gzip -d filename.gz 解压文件,解压后,源压缩文件消失
- gunzip filename.gz 解压文件, 解压后,源压缩文件消失
- gzip –c filename > /tmp/filename.gz指定压缩文件路径,并且源文件存在
- gzip –d –c /tmp/filename.gz > /目录/filename 解压文件到那个路径下,并且源压缩文件存在。
- gunzip –c /tmp/filename.gz > /目录/filename 解压文件到那个路径下,并且源压缩文件存在。
- zcat 1.txt.gz 查看.gz文件
- file /tmp/1.txt.gz 查看文件的属性
例子:查找/etc/下后缀为.conf的文件,并将它的内容追加到文件1.txt中,并且压缩它,然后再解压。
[[email protected] d6z]# find /etc/ -type f -name "*.conf" -exec cat {} >>1.txt \;[[email protected] d6z]# du -sh 1.txt4.0M1.txt //这里要注意一下,这个大小不太准确,这里多次追加会看到文件,du -sh 1.txt查看的文件数值不同,但在多次查看,文件大小会恢复正常。(跳转数值较大比,是因为这个文件本身存在很多空隙,最后在压缩并解压后,会发现大小会有不同)
[[email protected] d6z]# gzip 1.txt
[[email protected] d6z]# du -sh 1.txt.gz664K1.txt.gz
[[email protected] d6z]# gzip -d 1.txt.gz
[[email protected] d6z]# du -sh 1.txt2.5M1.txt
[[email protected] d6z]# gzip 1.txt
[[email protected] d6z]# du -sh 1.txt.gz664K1.txt.gz
[[email protected] d6z]# gunzip 1.txt.gz
[[email protected] d6z]# du -sh 1.txt2.5M1.txt
[[email protected] d6z]# gzip -c 1.txt > /tmp/1.txt.gz
[[email protected] d6z]# ls1.txt
[[email protected] d6z]# ls /tmp/1.txt.gz/tmp/1.txt.gz
[[email protected] d6z]# du -sh /tmp/1.txt.gz664K /tmp/1.txt.gz
[[email protected] d6z]# gzip -d -c /tmp/1.txt.gz > ./2.txt
[[email protected] d6z]# ls1.txt 2.txt
[[email protected] d6z]# wc -l 1.txt 2.txt 64790 1.txt 64790 2.txt 129580 总用量
[[email protected] d6z]# du -sh 1.txt 2.txt2.5M1.txt2.5M2.txt
[[email protected] d6z]# ls /tmp/1.txt.gz/tmp/1.txt.gz
[[email protected] d6z]# zcat /tmp/1.txt.gz
[[email protected] d6z]# file /tmp/1.txt.gz/tmp/1.txt.gz: gzip compressed data, was "1.txt", from Unix, last modified: Thu Nov 9 20:33:33 2018 /tmp/1.txt.gz 压缩数据是1.txt,基于unix平台,最后修改时间是2018年4月16日星期一
bzip命令的格式:bzip2 [-dz] filename ,压缩文件时加不加-z都一样,-d 解压缩。
bzip比gzip压缩更小,所耗费的CPU资源也最大(压缩的文件也是最小的)
- bzip2 1.txt / bzip2 -z 1.txt //压缩文件
- bzip2 -d 1.txt.bz2 / bunzip2 1.txt.bz2 //解压文件
- bzip -# 1.txt //#范围1-9,默认9
- 不能压缩目录
- bzcat 1.txt.bz2 //查看压缩文件
- bzip2 -c 1.txt > /root/1.txt.bz2 //指定压缩文件路径,并且源文件存在
- bzip2 -c -d /root/1.txt.bz2 > /tmp/1.txt.new2 //解压文件到指定路径下,并且源压缩文件存在
- File 1.txt.bz2 查看文件属性
第一次使用bzip2命令时提示没有这个命令,我们用yum安装一下
[[email protected] d6z]# bzip2 1.txt-bash: bzip2: 未找到命令
[[email protected] d6z]# yum install -y bzip2
[[email protected] d6z]# bzip2 1.txt
[[email protected] d6z]# ls1.txt.bz2 2.txt
[[email protected] d6z]# bzip2 -d 1.txt.bz2
[[email protected] d6z]# ls1.txt 2.txt
[[email protected] d6z]# bzip2 -c 1.txt > /tmp/1.txt.bz2
[[email protected] d6z]# ls /tmp/1.txt.bz2/tmp/1.txt.bz2
[[email protected] d6z]# ls1.txt 2.txt
[[email protected] d6z]# bzip2 -d -c /tmp/1.txt.bz2 > ./3.txt
[[email protected] d6z]# ls1.txt 2.txt 3.txt
[[email protected] d6z]# ls /tmp/1.txt.bz2/tmp/1.txt.bz2
[[email protected] d6z]# bzcat /tmp/1.txt.bz2
[[email protected] d6z]# file /tmp/1.txt.bz2/tmp/1.txt.bz2: bzip2 compressed data, block size = 900k //bzip2压缩数据,大小为900k
xz命令格式:xz[-zd] filename 压缩文件加不加-z都可以,-d解压缩。
xz压缩文件比bzip2更小,所耗费的CPU资源也最大(压缩的文件也是最小的)
- xz 1.txt / xz -z 1.txt //压缩文件
- xz -d 1.txt.xz / unxz 1.txt.xz //解压缩文件
- xz -# 1.txt //#范围1-9,默认9
- 不能压缩目录
- xzcat 1.txt.xz //查看压缩文件内容
- xz -c 1.txt > /root/1.txt.xz //指定压缩文件路径,并且源文件存在
- xz -d -c /root/1.txt.xz > 1.txt.new3 //解压文件到指定路径下,并且源压缩文件存在
- file 1.txt.xz查看文件属性
- 压缩文件1.txt
[[email protected] d6z]# xz -d 1.txt.xz
[[email protected] d6z]# ls1.txt 2.txt 3.txt
[[email protected] d6z]# xz -c 1.txt > /tmp/1.txt.xz
[[email protected] d6z]# ls1.txt 2.txt 3.txt
[[email protected] d6z]# ls /tmp/1.txt.xz/tmp/1.txt.xz
[[email protected] d6z]# xz -d -c /tmp/1.txt.xz > ./4.txt
[[email protected] d6z]# ls1.txt 2.txt 3.txt 4.txt
[[email protected] d6z]# ls /tmp/1.txt.xz/tmp/1.txt.xz
[[email protected] d6z]# file /tmp/1.txt.xz/tmp/1.txt.xz: XZ compressed data //xz压缩数据。
[[email protected] d6z]# du -sh
/tmp/1.txt.gz
/tmp/1.txt.bz2
/tmp/1.txt.xz664K
/tmp/1.txt.gz260K
/tmp/1.txt.bz260K
/tmp/1.txt.xz
- zip 1.txt.zip 1.txt //压缩文件
- zip -r 123.zip 123/ //压缩目录
- unzip 1.txt.zip //解压
- unzip 123.zip -d /root/456/ //解压文件,并指定解压到那个目录下
- 不能查看压缩文件的内容,只能查看内容列表
- unzip -l 123.zip //查看压缩文件的内容列表
- zip压缩文件后,源文件不消失
[[email protected] d6z]# zip 1.txt.zip 1.txt-bash: zip: 未找到命令
[[email protected] d6z]# yum install -y zip
[[email protected] d6z]# zip 1.txt.zip 1.txt
adding: 1.txt (deflated 74%)
[[email protected] d6z]# ls1.txt 1.txt.zip 2.txt 3.txt 4.txt test
[[email protected] d6z]# du -sh 1.txt.zip664K1.txt.zip
[[email protected] d6z]# zip -r test.zip test
adding: test/ (stored 0%)
adding: test/3.txt (deflated 74%)
adding: test/4.txt (deflated 74%)
[[email protected] d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.zip
[[email protected] d6z]# du -sh test.zip1.3M test.zip
[[email protected] d6z]# du -sh test5.0Mtest
[[email protected] d6z]# unzip 1.txt.zip-bash: unzip: 未找到命令
[[email protected] d6z]# yum install -y unzip
[[email protected] d6z]# unzip 1.txt.zip Archive: 1.txt.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A //A表示全部覆盖,N表示全部不覆盖 inflating: 1.txt
[[email protected] d6z]# ls1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.zip
[[email protected] d6z]# unzip test.zip Archive: test.zip replace test/3.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A inflating: test/3.txt inflating: test/4.txt
[[email protected] d6z]# unzip test.zip -d /tmp/testArchive: test.zip creating: /tmp/test/test/ inflating: /tmp/test/test/3.txt inflating: /tmp/test/test/4.txt
[[email protected] d6z]# ls /tmp/test 333 test test1 test2
[[email protected] d6z]# unzip -l test.zip Archive: test.zip Length Date Time Name --------- ---------- ----- ---- 0 04-17-2018 21:34 test/ 2572100 04-17-2018 21:33 test/3.txt 2572100 04-17-2018 21:34 test/4.txt
tar
tar 命令还可以在打包的同时支持gzip压缩,bzip压缩和xz压缩
打包并压缩的使用方法:
https://blog.****.net/freeking101/article/details/51480295
- tar本身是一个打包工具,可以把目录打包成一个文件,它把所有的文件整合成一个大文件,方便复制或者移动。
- 命令格式:tar [-zjxcvfpP] filename.tar
- tar打包或解包均会直接覆盖原文件和目录,不会提示覆盖信息
- -z表示同时使用gzip压缩
- -j表示同时用bzip压缩
- -J表示同时用xz压缩
- -c表示建立一个tar包或者压缩文件包
- -x表示解包或者解压
- -v表示可视化
- -f后面跟文件名(-f filename,表示压缩后的文件名为filename)注意:如果多个参数组合的情况下,-f要写在最后面。
- -t表示查看tar包里的文件
- --exclude filename 表示在打包或压缩时,不要将某个文件不包含在里面。
- 打包或者解包,源文件都存在。
- 打包后产生的文件与打包前的文件在同一目录下。
- tar -cvf 123.tar 123 // 打包目录123
- tar -cvf aming.tar 1.txt 123 //打包目录123和文件1.txt
- tar -xvf aming.tar //解包
- tar -tf aming.tar //查看打包文件
- tar -cvf aming.tar --exclude 1.txt --exclude 2 123 //打包目录123,单不包括文件1.txt和2
- 打包目录test和文件1.txt,2.txt
[[email protected] d6z]# tar -cvf test.tar test 1.txt 2.txttest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.tar test.zip
[[email protected] d6z]# tar -tf test.tartest/test/3.txtJ
[[email protected] d6z]# tar -xvf test.tartest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# tar -cvf test.tar --exclude 3.txt test 1.txt 2.txttest/test/4.txt 1.txt 2.txt
[[email protected] d6z]# tar -cvf test.tar --exclude 3.txt --exclude 4.txt test 1.txt 2.txttest/ 1.txt 2.txt
- tar -zcvf 123.tar.gz 123
- tar -zxvf 123.tar.gz
- tar -jcvf 123.bz2 123
- tar -jxvf 123.bz2
- tar -Jcvf 123.xz 123
- tar -Jxvf 123.xz
- tar -tf 123.bz2 / tar -tf 123.gz / tar -tf 123.xz
[[email protected] d6z]# tar -zcvf test.tar.gz test 1.txt 2.txttest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# ls 1.txt 1.txt.zip 2.txt 3.txt 4.txt test test.tar test.tar.gz test.zip
[[email protected] d6z]# tar -tf test.tar.gztest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# tar -zxvf test.tar.gztest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# tar -jcvf test.tar.bz2 test 1.txt 2.txttest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# tar -jxvf test.tar.bz2test/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# tar -Jcvf test.tar.xz test 1.txt 2.txttest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# tar -Jxvf test.tar.xztest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# tar tf test.tar.xztest/test/3.txttest/4.txt 1.txt 2.txt
[[email protected] d6z]# du -sh test.tar.gz test.tar.bz2 test.tar.xz2.6Mtest.tar.gz988Ktest.tar.bz264Ktest.tar.xz
vim /etc/fstab
mount
mount -a
mount -a
/etc/fstab
mount -all
Defaults
同事具有rw,suid,dev,exec,auto,nouser,async等默认参数的设置