国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux學習筆記(7)Linux常用命令之壓縮解壓命令

2024-06-28 13:22:25
字體:
來源:轉載
供稿:網友
linux學習筆記(7)Linux常用命令之壓縮解壓命令(1)gzip

gzip命令用于壓縮文件,英文原意為GNU zip,所在路徑/bin/gzip,其語法格式為:

gzip [文件]

壓縮后的文件格式為.gz。

例:將/etc目錄下的services文件拷貝至/tmp目錄,并采用gzip進行壓縮。

[root@localhost tmp]# cp /etc/services services[root@localhost tmp]# lsservices[root@localhost tmp]# gzip services[root@localhost tmp]# lsservices.gz

注:gzip只能壓縮文件,無法壓縮目錄;gzip命令不保留源文件,上例就可以看出。

(2)gunzip

gunzip命令用于解壓縮文件,英文原意為GNU unzip,所在路徑為/bin/gunzip,其語法格式為:

gunzip [壓縮文件]

例:解壓縮新創建的壓縮文件

[root@localhost tmp]# gunzip services.gz[root@localhost tmp]# lsservices

注:也可以使用gzip -d解壓縮文件;gunzip執行后不保留源文件。

(3)tar

tar命令用于打包目錄,所在路徑為/bin/tar,其語法格式為:

tar 選項[-zcf] [壓縮后的文件名] [目錄]

其中,-c選項表示打包;-v選項表示顯示詳細信息,-f選項指定文件名,-z選項表示打包的同時進行壓縮,壓縮后的文件格式為.tar.gz。

例:在/tmp目錄下創建test/test1和test/test2目錄,然后對test目錄進行打包。

[root@localhost tmp]# mkdir -p test/test1 test/test2[root@localhost tmp]# tar -czvf test.tar.gz testtest/test/test2/test/test1/[root@localhost tmp]# ls -ltotal 636-rw-r--r--. 1 root root 641020 Jan  1 22:17 servicesdrwxr-xr-x. 4 root root   4096 Jan  1 22:25 test-rw-r--r--. 1 root root    134 Jan  1 22:26 test.tar.gz

tar解壓縮的語法格式為:

tar -xzvf [壓縮文件]

其中,-x選項表示解包,-v選項表示顯示詳細信息,-f選項表示指定解壓文件,-z選項表示解壓縮。

例:刪除創建的test目錄,然后解壓縮test.tar.gz

[root@localhost tmp]# rm -rf test[root@localhost tmp]# lsservices  test.tar.gz[root@localhost tmp]# tar -xzvf test.tar.gztest/test/test2/test/test1/[root@localhost tmp]# lsservices  test  test.tar.gz
(4)zip

zip命令用于壓縮文件或目錄,所在路徑為/usr/bin/zip,其語法格式為:

zip 選項[-r] [壓縮后的文件名] [文件或目錄]

其中,-r選項表示壓縮目錄,壓縮后的文件格式為.zip。

例:將services文件進行zip壓縮:

[root@localhost tmp]# zip services.zip services  adding: services (deflated 80%)[root@localhost tmp]# lsservices  services.zip  test  test.tar.gz

注:zip格式在Linux和Windows中均存在;壓縮比并不是很高。

(5)unzip

unzip命令用于解壓.zip格式的文件,所在路徑為/usr/bin/unzip,其語法格式為:

unzip [壓縮文件]

例:解壓services.zip文件

[root@localhost tmp]# unzip services.zipArchive:  services.ziPReplace services? [y]es, [n]o, [A]ll, [N]one, [r]ename:

源文件存在,解壓時詢問是否替換。

(6)bzip2

bzip2是gzip的升級版本,也用于壓縮文件,所在路徑為/usr/bin/bzip2,其語法格式為:

bzip2 選項[-k] [文件]

其中-k選項產生壓縮文件后保留源文件。壓縮后的文件格式為.bz2。

使用tar命令可以將目錄保存為.bz2文件,其格式為:

tar 選項[-cjvf] [壓縮后文件名] [目錄]

其中-j選項即表示壓縮為.tar.bz2文件。

例:使用bzip2命令對services文件進行壓縮,隨后將test目錄也進行壓縮

[root@localhost tmp]# bzip2 -k services[root@localhost tmp]# lsservices  services.bz2  services.zip  test  test.tar.gz[root@localhost tmp]# tar -cjvf test.tar.bz2 testtest/test/test2/test/test1/[root@localhost tmp]# lsservices  services.bz2  services.zip  test  test.tar.bz2  test.tar.gz
(7)bunzip2

bunzip2命令用于解壓縮.bz2文件,所在路徑為/usr/bin/bunzip2,其語法格式為:

bunzip2 選項[-k] [壓縮文件]

其中-k表示解壓縮后保留源文件。

使用tar命令也可以解壓縮.bz2的文件,其格式為:

tar 選項[-xjvf] [壓縮文件]

例:刪除services文件和test文件夾,然后分別解壓縮:

[root@localhost tmp]# rm -rf services test[root@localhost tmp]# lsservices.bz2  services.zip  test.bz2  test.tar.gz[root@localhost tmp]# bunzip2 services.bz2[root@localhost tmp]# tar -xjvf test.tar.bz2test/test/test2/test/test1/[root@localhost tmp]# lsservices  services.zip  test  test.tar.bz2  test.tar.gz

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 徐州市| 淮南市| 乳山市| 讷河市| 荥阳市| 罗定市| 绍兴市| 青海省| 天长市| 武宣县| 板桥市| 万荣县| 巴青县| 鄂托克旗| 延津县| 广昌县| 当涂县| 巴彦县| 潮州市| 钟山县| 望江县| 松潘县| 兴文县| 德清县| 阳谷县| 班玛县| 连城县| 怀远县| 从江县| 南木林县| 邓州市| 元氏县| 偏关县| 牟定县| 湖州市| 钦州市| 清流县| 沁阳市| 邹城市| 嘉义县| 汉阴县|