linux打包tar包命令,Linux压缩打包方法连载之一:tar命令

Linux压缩打包方法有很多种,以下讲了tar命令的概念,同时文列举了多种范例供大家查看,希望对大家有所帮助....

tar命令

[root@linux ~]# tar [-cxtzjvfpPN] 文件与目录 ....

参数:

-c :建立一个压缩文件的参数指令(create 的意思);

-x :解开一个压缩文件的参数指令!

-t :查看 tarfile 里面的文件!

特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!因为不可能同时压缩与解压缩。

-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?

-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?

-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!

-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!

例如使用『 tar -zcvfP tfile sfile』就是错误的写法,要写成『 tar -zcvPf tfile sfile』才对喔!

-p :使用原文件的原来属性(属性不会依据使用者而变)

-P :可以使用绝对路径来压缩!

-N :比后面接的日期(yyyy/mm/dd)还要新的才会被打包进新建的文件中!

--exclude FILE:在压缩的过程中,不要将 FILE 打包!

范例一:

将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar

[root@linux ~]# tar -cvf /tmp/etc.tar /etc <==仅打包,不压缩!

[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc <==打包后,以 gzip 压缩

[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc <==打包后,以 bzip2 压缩

◆ 特别注意,在参数 f 之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。

◆如果加 z 参数,则以 .tar.gz 或 .tgz 来代表 gzip 压缩过的 tar file ~

◆如果加 j 参数,则以 .tar.bz2 来作为附档名啊~

◆上述指令在执行的时候,会显示一个警告讯息:

◆『tar: Removing leading `/' from member names』那是关於绝对路径的特殊设定。

范例二:

查阅上述 /tmp/etc.tar.gz 文件内有哪些文件?

[root@linux ~]# tar -ztvf /tmp/etc.tar.gz

◆ 由於我们使用 gzip 压缩,所以要查阅该 tar file 内的文件时,

◆就得要加上 z 这个参数了!这很重要的!

范例三:

将 /tmp/etc.tar.gz 文件解压缩在 /usr/local/src 底下

[root@linux ~]# cd /usr/local/src

[root@linux src]# tar -zxvf /tmp/etc.tar.gz

◆ 在预设的情况下,我们可以将压缩档在任何地方解开的!以这个范例来说,

◆我先将工作目录变换到 /usr/local/src 底下,并且解开 /tmp/etc.tar.gz ,

◆则解开的目录会在 /usr/local/src/etc 呢!另外,如果您进入 /usr/local/src/etc

◆则会发现,该目录下的文件属性与 /etc/ 可能会有所不同喔!

范例四:

在 /tmp 底下,我只想要将 /tmp/etc.tar.gz 内的 etc/passwd 解开而已

[root@linux ~]# cd /tmp

[root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd

◆我可以透过 tar -ztvf 来查阅 tarfile 内的文件名称,如果单只要一个文件,

◆就可以透过这个方式来下达!注意到! etc.tar.gz 内的根目录 / 是被拿掉了!

范例五:

将 /etc/ 内的所有文件备份下来,并且保存其权限!

[root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etc

◆这个 -p 的属性是很重要的,尤其是当您要保留原本文件的属性时!

范例六:

在 /home 当中,比 2005/06/01 新的文件才备份

[root@linux ~]# tar -N '2005/06/01' -zcvf home.tar.gz /home

范例七:

我要备份 /home, /etc ,但不要 /home/dmtsai

[root@linux ~]# tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc

范例八:

将 /etc/ 打包后直接解开在 /tmp 底下,而不产生文件!

[root@linux ~]# cd /tmp

[root@linux tmp]# tar -cvf - /etc | tar -xvf -

◆ 这个动作有点像是 cp -r /etc /tmp 啦~依旧是有其有用途的!

◆要注意的地方在於输出档变成 - 而输入档也变成 - ,又有一个 | 存在~

◆ 这分别代表 standard output, standard input 与管线命令啦!

◆这部分我们会在 Bash shell 时,再次提到这个指令跟大家再解释啰!

以上为Linux压缩打包方法中的tar命令介绍,下面将给大家介绍gzip, zcat 命令

【编辑推荐】

【责任编辑:薛辈辈 TEL:(010)68476606】

点赞 0

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440433.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【计蒜客 - 2019南昌邀请赛网络赛 - I】Max answer(单调栈,RMQ)

题干&#xff1a; Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values in the interval, multiplied by the smallest value in the interval. Now she is planning to find the max value of the intervals in her arr…

linux联想电脑wifi密码,联想笔记本Y7000—ubuntu16.4无法开启wifi的解决办法

一、问题描述本人使用的是联想游戏本Y7000&#xff0c;默认装入Win10系统&#xff0c;然当装入Ubuntu16.04双系统时&#xff0c;会出现无线硬件开关关闭的问题&#xff0c;当然也就无法连网。使用rfkill list all会出现如下提示0:ideapad_wlan: Wireless LANSoft blocked: noHa…

【HDU - 6514】Monitor(二维差分,前缀和)

题干&#xff1a; Monitor Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 163840/163840 K (Java/Others) Total Submission(s): 872 Accepted Submission(s): 145 Problem Description Xiaoteng has a large area of land for growing crops, and the land…

linux网卡限速tc,linux tc 对本机网卡限速

今天由于项目要测试在网络环境不好的情况下&#xff0c;会不会对平台有所影响&#xff0c;要求测试限制服务器流量&#xff0c;我想到了TC&#xff0c;我对TC不是很了解&#xff0c; google了一下&#xff0c;看到了不少文章都是做路由用的&#xff0c;对我来说不是很实用&…

【ZOJ - 3715】Kindergarten Election(枚举得票数,贪心)

题干&#xff1a; At the beginning of the semester in kindergarten, the n little kids (indexed from 1 to n, for convenience) in class need to elect their new leader. The ith kid will vote for his best friend fi (where 1 ≤ fi ≤ n, and its too shame to vo…

修改DNS的Linux脚本,Shell脚本-配置网络

原先学习过shll但是只是了解一下它的语法而已&#xff0c;在平时中并没有使用&#xff0c;在暑假的时候又想起了shell&#xff0c;所以又回顾了一下&#xff0c;学习后一定要用&#xff0c;这样才能掌握。最近实验室刚装好机子&#xff0c;什么都要配置一下&#xff0c;包括网络…

【ZOJ - 3872】Beauty of Array(思维,计算贡献,枚举)

题干&#xff1a; Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A. Input There…

linux 使用gzip压缩打包的文件,linux常用的解压,压缩,打包

gzip zcat[rootlinux ~]# gzip [-cdt#] 文件名[rootlinux ~]# zcat 文件名.gz参数&#xff1a;-c : 将压缩的数据输出到屏幕上&#xff0c;可通过数据流重导向来处理-d &#xff1a;解压缩参数-t &#xff1a; 可以用来检验一个压缩文件的一致性&#xff5e;看看文件有无错误-#…

【POJ - 1836】Alignment(dp,LIS,最长上升子序列类问题)

题干&#xff1a; In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the …

Windows共享Linux打印机,linux – 如何为cups客户端构建windows共享打印机的url

从this page开始&#xff1a;smbThis backend sends print files to printers shared by a Windows host. Examplesof CUPS device-URIs that may be used includes:smb://workgroup/server/printersharenamesmb://server/printersharenamesmb://username:passwordworkgroup/se…

【HDU - 1080】Human Gene Functions(dp,可编辑距离类问题)

题干&#xff1a; 给你两个DNA序列&#xff08;长度不一定相同&#xff09;&#xff0c;你可以在其中任意位置上加入空格&#xff0c;使得最终他俩长度相同&#xff0c;最终相同长度的两个DNA序列会有个相似度比较&#xff08;每个字符相对应的比较&#xff09;&#xff0c;问…

linux 对硬盘重新分区,硬盘重新分区后,linux的硬盘表的重新设置

硬盘重新分区后&#xff0c;linux的硬盘表的重新设置发布时间:2007-12-29 16:04:19来源:红联作者:Alwaysfirm会硬盘分区后uuid会变动&#xff0c;导致linux挂载硬盘出错。-----什么是uuid?UUID&#xff0c;全称Universally Unique Identifier它是一个128位&#xff0c;16字节的…

【POJ - 1837】Balance(dp及其优化)

题干&#xff1a; Gigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. It orders two arms of negligible weight and each arms length is 15. Some hooks are attached to these arm…

linux awk 时间范围,linux下使用awk命令按时间段筛选日志

需求很多时候我们需要按照时间段来进行日志的分析&#xff0c;比如说查看上午的&#xff0c;或者某月某日的的具体日志&#xff0c;就不能简单实用tail -f或者head -n命令了。这个时候我们需要借用awk。命令zcat com.log20160529.gz | grep dianping_reply.log| awk {split($4,…

【CodeForces - 1153D】Serval and Rooted Tree(树形dp)

题干&#xff1a; Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before. As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree. …

【OpenJ_Bailian - 4117】简单的整数划分问题(dp)

题干&#xff1a; 将正整数n 表示成一系列正整数之和&#xff0c;nn1n2…nk, 其中n1>n2>…>nk>1 &#xff0c;k>1 。 正整数n 的这种表示称为正整数n 的划分。正整数n 的不同的划分个数称为正整数n 的划分数。 Input 标准的输入包含若干组测试数据。每组测试…

【ZOJ - 3778】Talented Chef(贪心)

题干&#xff1a; As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same time. Tonight he is going to have a hearty dinner with his girlfriend at his home. Of course, Coach Gao is going to cook all dishes himself, in …

实验楼Linux基础挑战2答案,实验楼-Linux基础-实验二 Linux的基本概念及操作

一、实验介绍1.1 实验内容实验楼环境介绍常用 Shell 命令及快捷键Linux 使用小技巧1.2 实验知识点Linux 基本命令通配符的使用查看帮助文档二、桌面环境1.Linux 桌面环境介绍相对于现在的 Windows 系统&#xff0c;UNIX/Linux 本身是没有图形界面的&#xff0c;我们通常在 UNIX…

【ZOJ - 3780】Paint the Grid Again(拓扑排序,图论,证明性质)

题干&#xff1a; Leo has a grid with N N cells. He wants to paint each cell with a specific color (either black or white). Leo has a magical brush which can paint any row with black color, or any column with white color. Each time he uses the brush, the…

linux bin su,linux – su:/ bin / bash:资源暂时不可用

无法将用户切换为postgres.postgres用户的ulimit设置设置了合理的限制.我们没有达到最高限度./ var / log / messages中没有错误.BETA -bash-4.2# sudo su - postgressu: /bin/bash: Resource temporarily unavailable设置&#xff1a;BETA -bash-4.2# ps -auxww | grep -i pos…