昨日回顧
1.find文件查找的命令
2.find通過(guò)哪些方式查找文件
.名稱
.大小
.類型
.時(shí)間
.用戶
.用戶組
.過(guò)濾內(nèi)容grep使用
3.動(dòng)作處理Action
.列出結(jié)果 -print
.以長(zhǎng)格式列出結(jié)果 -ls
.刪除查找的結(jié)果 -delete
.執(zhí)行command命令
-ok command\锨亏;#會(huì)提示
-exec command ; #可以執(zhí)行任何shell命令(效率不是太高)
| xarge commd將find結(jié)果作為參數(shù)傳遞給后面的命令
今日內(nèi)容
1什么是文件壓縮遮怜?
將多個(gè)文件或目錄合并成為一個(gè)特殊的文件
2為什么要對(duì)文件進(jìn)行壓縮?
減少文件的體積
加快資源的傳輸
節(jié)省網(wǎng)絡(luò)的寬帶
3windows的壓縮包與linux的壓縮包能否互通摊聋?
windows:rar zip 其實(shí)支持很多類型的壓縮
linux:zip tar.gz ...
4*linux 下壓縮包有哪些常見(jiàn)的類型
格式 壓縮工具
.zip zip壓縮工具 (必須要會(huì)使用的)
.gz
gzip壓縮工具,只能壓縮文件璧瞬,會(huì)刪除原文件(通常配合tar使
用)
.bz2
bzip2壓縮工具户辫,只能壓縮文件,會(huì)刪除原文件(通常配合tar使
用)
.tar.gz 先使用tar命令歸檔打包嗤锉,然后使用gzip壓縮 (必須會(huì)的)
.tar.bz2先使用tar命令歸檔打包渔欢,然后使用bzip壓縮 (順帶就會(huì))
- 5 linux gzip工具使用
1.gzip打包與壓縮,僅對(duì)文件有效
2.gzip filename 打包
3.gzip -d filename.gz
4.zcat filename.gz 查看包內(nèi)文件的內(nèi)容
[root@xuliangwei ~]# yum install gzip -y
[root@xuliangwei ~]# gzip file #對(duì)文件進(jìn)行壓縮
[root@xuliangwei ~]# zcat file.gz #查看gz壓縮后的文件
[root@xuliangwei ~]# gzip -d file.gz #解壓gzip的壓縮包
使用場(chǎng)景:當(dāng)需要讓某個(gè)文件快速關(guān)閉和快速啟用.
[root@xuliangwei ~]# gzip CentOS-Vault.repo -->
CentOS-Vault.repo.gz
[root@xuliangwei ~]# zcat CentOS-Vault.repo.gz --> 查
看不想解壓的壓 - 6 linux zip 工具使用
默認(rèn)情況下沒(méi)有zip和unzip工具瘟忱,需要進(jìn)行安裝
[root@xuliangwei ~]# yum install zip unzip -y
1.壓縮文件為zip包
[root@xuliangwei ~]# zip filename.zip filename
[root@xuliangwei ~]# unzip -l filename.zip #查看包內(nèi)
容
2.壓縮目錄為zip包
[root@xuliangwei ~]# zip -r dir.zip dir/
3.查看zip壓縮包是否是完整的
[root@xuliangwei ~]# zip -T filename.zip
test of filename.zip OK
4.不解壓壓縮查看壓縮包中的內(nèi)容
[root@xuliangwei ~]# unzip -l filename.zip
[root@xuliangwei ~]# unzip -t filename.zip #檢測(cè)文件是
否都o(jì)k
5.解壓zip文件包, 默認(rèn)解壓至當(dāng)前目錄
[root@xuliangwei ~]# unzip filename.zip
6.解壓zip內(nèi)容至/opt目錄
[root@xuliangwei ~]# unzip filename.zip -d /opt/
打包
zip -r /tmp/test.zip file dir/
解包
unzip tt.zip
unzip tt.zip -d /opt - 7.linux tar 工具使用
tar是linux下最常用的壓縮與解壓縮奥额,支持文件和目錄的壓縮歸檔
語(yǔ)法:tar [-zjxcvfpP] filename
c #創(chuàng)建新的歸檔文件
x #對(duì)歸檔文件解包
t #列出歸檔文件里的文件列表
f #指定包文件名,多參數(shù)f寫(xiě)最后
z #使用gzip壓縮歸檔后的文件(.tar.gz)
j #使用bzip2壓縮歸檔后的文件(.tar.bz2)
J #使用xz壓縮歸檔后的文件(tar.xz)
C #指定解壓目錄位置
X #排除多個(gè)文件(寫(xiě)入需要排除的文件名稱)
h #打包軟鏈接
--exclude #在打包的時(shí)候?qū)懭胄枰懦募蚰夸?br> 常用打包與壓縮組合
cjf #打包tar.bz格式
cJf #打包tar.xz格式 使用田少,不考慮
zxf #解壓tar.gz格式
jxf #解壓tar.bz格式
czr #打包tar.gz格式 ()
tf #查看壓縮包內(nèi)容
xf #自動(dòng)選擇解壓模式 ()
打包
tar czf test.tar.gz test/ test2/ #以gzip方式壓縮
tar cjf test.tar.bz2 dir.txt dir/ #以bz2方式壓縮
查看包內(nèi)容
tar tf test.tar.gz
tar tf test.tar.bz2
tar tf test.tar.xz
解壓
tar xf test.tar.gz
tar xf test.tar.bz2
tar xf test.tar.xz
tar xf root.tar.gz -C /tmp/ #解壓至指定目錄
打包/tmp下所有文件
find tmp/ -type f | xargs tar czf tmp.tar.gz
tar czf tmp.tar.gz $(find /tmp/ -type f)
3.打包鏈接文件,打包鏈接文件的真實(shí)文件
[root@xuliangwei /]# tar czfh local.tar.gz
etc/rc.local
4.排除操作
tar czf etc.tar.gz /etc/ --exclude=etc/services
tar czf etc.tar.gz /etc/ --exclude=etc/passwd --
exclude=etc/shadow
5.將需要排除的文件寫(xiě)入文件中
[root@oldboyedu opt]# cat pc.txt
etc/gshadow
etc/gshadowetc/passwd
etc/passwdetc/shadowetc/shadow
etc/security/opasswd
etc/pam.d/passwd
[root@oldboyedu opt]# tar czXf pc.txt etc.tar.gz
/etc/
1.環(huán)境準(zhǔn)備
[root@xuliangwei ~]# yum install mariadb-server
[root@xuliangwei ~]# systemctl start mariadb
[root@xuliangwei ~]# mkdir /backup
案例1.mysql備份及恢復(fù)
[root@xuliangwei ~]# tar cJf /backup/mysql.tar.xz
/var/lib/mysql
[root@xuliangwei ~]# tar xf /backup/mysql.tar.xz -C /
案例2 mysql備份及恢復(fù)
[root@xuliangwei ~]# cd /var/lib/mysql
[root@xuliangwei mysql]# tar cJf /backup/mysql.tar.xz
[root@xuliangwei mysql]# tar xf /backup/mysql.tar.xz -
C /var/lib/mysql