使用cat命令进行文件的纵向合并,具体命令如下所示(注意:>代表将左边命令的执行结果以覆盖的方式放到右边,>>代表将左边命令的执行结果追加到右边)

关于tar命令的一些用法:

tar 命令用来将很多文件打包成一个单一的磁带或者磁盘归档,并可从归档文件恢复出文件列表。当你需要发送大量文件时或者传输文件时非常有用。

tar 的语法:

# tar [options] file.tar file1 file2 .. .. ..

file.tar 是 tar 归档文件,而其他 file1 和 file2 等等是要被打包的文件。

例如我们有两个文件 file1.txt 和 file2.txt

[root@localhost TAR]# ll
total 8
-rw-r--r--. 1 root root 2770 Feb 7 22:37 file1.txt
-rw-r--r--. 1 root root 887 Feb 7 22:38 file2.txt

tar 常用的使用场景

创建一个 tar 文件
语法:

# tar -cf archive.tar files .. ..

示例:

[root@localhost TAR]# tar -cf file.tar file1.txt file2.txt
[root@localhost TAR]# ll file.tar
-rw-r--r--. 1 root root 10240 Feb 7 22:42 file.tar

列出 tar 文件中的所有文件列表

# tar -tf archive.tar

示例:

[root@localhost TAR]# tar -tf file.tar
file1.txt
file2.txt

从 tar 中提取所有文件

tar -xf archive.tar

示例

[root@localhost TAR]# tar -xf file.tar
[root@localhost TAR]# ll
total 20
-rw-r--r--. 1 root root 2770 Feb 7 22:37 file1.txt
-rw-r--r--. 1 root root 887 Feb 7 22:38 file2.txt
-rw-r--r--. 1 root root 10240 Feb 7 22:42 file.tar

参数选项

1, -v, –verbose
verbosely list files processed:
Syntax:
List all files in an archive.tar verbosely:

tar -tvf archive.tar

Example:

[root@localhost TAR]# tar -tvf file.tar
-rw-r--r-- root/root 2770 2014-02-07 22:37 file1.txt
-rw-r--r-- root/root 887 2014-02-07 22:38 file2.txt

2, -c, –create
创建新的归档文件

3, -t, –list
列出归档文件中的内容

4, -x, –extract, –get
从归档中提取文件

5, -d, –diff, –compare
比较归档和文件系统的差异
Example:

[root@localhost TAR]# tar -tf file.tar
file2.txt
file3.txt
file1.txt
[root@localhost TAR]# tar -df file.tar file1.txt file2.txt file4.txt
tar: file4.txt: Not found in archive
tar: Exiting with failure status due to previous errors
----Verbosely----
[root@localhost TAR]# tar -dvf file.tar file1.txt file2.txt
file2.txt
file1.txt
[root@localhost TAR]# tar -dvf file.tar file1.txt file2.txt file6.txt
file2.txt
file1.txt
tar: file6.txt: Not found in archive
tar: Exiting with failure status due to previous errors

6, –delete
从归档中删除某文件
示例:
从归档 file.tar 中删除 file1.txt

[root@localhost TAR]# tar --delete -f  file.tar  file1.txt
[root@localhost TAR]# tar -tf file.tar
file2.txt

7, -r, –append
追加文件到归档中
示例:
追加 file3.txt 到 file.tar

[root@localhost TAR]# tar -rf file.tar file3.txt
[root@localhost TAR]# tar -tf file.tar
file1.txt
file2.txt
file3.txt

8, -A, –catenate, –concatenate
将一个tar 归档追加到另外一个归档文件中
创建另外一个 tar 文件

[root@localhost TAR]# tar -cf archive.tar file1.txt file3.txt

追加方法:

[root@localhost TAR]# tar -Af file.tar archive.tar
[root@localhost TAR]# tar -tf file.tar
file2.txt
file3.txt
file1.txt
file1.txt
file3.txt

9, –test-label
测试归档卷标并退出

10, -u, –update
只追加最新的文件
示例:

[root@localhost TAR]# tar -tf file.tar
file1.txt
file2.txt
[root@localhost TAR]# tar -uf file.tar file1.txt file3.txt file2.txt
[root@localhost TAR]# tar -tf file.tar
file1.txt
file2.txt
file3.txt

11, -C, –directory=DIR
更改目录到 DIR

例如:
提取文件到另外一个目录

[root@localhost TAR]# tar -xvf file.tar -C /root/TAR2
file1.txt
file2.txt
[root@localhost TAR]# cd -
/root/TAR2
[root@localhost TAR2]# ll
total 28
-rw-r--r--. 1 root root 23250 Feb 7 23:11 file1.txt
-rw-r--r--. 1 root root 887 Feb 7 22:38 file2.txt

12, -p, –preserve-permissions
抽取文件时保留原有的文件权限

压缩归档文件,使用 BZIP 和 GZIP 两种方法

跟压缩相关的参数

13, -j, –bzip2
使用 bzip2 对归档进行压缩

示例:

[root@localhost TAR]# tar -jcf file.tar.bz file2.txt file1.txt
[root@localhost TAR]# ll
total 128
-rw-r--r--. 1 root root 23250 Feb 7 23:11 file1.txt
-rw-r--r--. 1 root root 887 Feb 7 22:38 file2.txt
-rw-r--r--. 1 root root 30720 Feb 7 23:30 file.tar
-rw-r--r--. 1 root root 1797 Feb 7 23:42 file.tar.bz

请看,上面的文件大小通过 BZIP 降低到 1797 字节。

14, -z, –gzip
使用 gzip 压缩归档

示例:

[root@localhost TAR]# tar -zcf file.tar.gz file2.txt file1.txt
[root@localhost TAR]# ll
total 132
-rw-r--r--. 1 root root 23250 Feb 7 23:11 file1.txt
-rw-r--r--. 1 root root 887 Feb 7 22:38 file2.txt
-rw-r--r--. 1 root root 30720 Feb 7 23:30 file.tar
-rw-r--r--. 1 root root 1797 Feb 7 23:42 file.tar.bz
-rw-r--r--. 1 root root 1673 Feb 7 23:45 file.tar.gz

正文处理命令及tar命令的更多相关文章

  1. linux基础-第八单元 正文处理命令及tar命令

    第八单元 正文处理命令及tar命令 使用cat命令进行文件的纵向合并 两种文件的纵向合并方法 归档文件和归档技术 归档的目的 什么是归档 tar命令的功能 tar命令的常用选项 使用tar命令创建.查 ...

  2. Linux基础(3)- 正文处理命令及tar命令、vi编辑器、硬盘分区、格式化及文件系统的管理和软连接、硬连接

    一.正文处理命令及tar命令 1)  将用户信息数据库文件和组信息数据库文件纵向合并为一个文件1.txt(覆盖) 2)  将用户信息数据库文件和用户密码数据库文件纵向合并为一个文件2.txt(追加) ...

  3. 第八单元 正文处理命令及tar命令

    使用cat命令进行文件的纵向合并  两种文件的纵向合并方法  归档文件和归档技术 归档的目的 什么是归档 tar命令的功能 tar命令的常用选项 使用tar命令创建.查看及抽取归档文件 使用tar命令 ...

  4. Linux基础-4.正文处理命令及tar命令

    1.使用cat命令进行文件的纵向合并 1)掌握使用cat命令的纵向合并 a)例如:使用cat命令将test1.file1.txt和file2这三个文件纵向合并为file文件的命令为: cat test ...

  5. Linux 正文处理命令及tar命令 利用vi编辑器创建和编辑正文文件

    要点回顾 1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) cp /etc/passwd . cat ./passwd >1.txt cp /etc/group ...

  6. find命令和tar命令的使用

    tar命令 tar -zcvf small.tar.gz small(目录名) (压缩) tar -zxvf small.tar.gz -C small(目录名) (解压到指定目录) find 命令 ...

  7. Linux使用快捷键,who命令,rm命令,ps命令,cd,命令kill命令,find命令,grep命令,tar命令(gz、tar、bz2),用户管理,vim配置的一部分,相关命令

    1.进入Ubuntu开场后的终端窗口的快捷键是:           ctrl + alt+t:通过这个命令能够打开终端. ctrl + alt+t:通过这个命令能够打开终端. 再开一个tab选项卡式 ...

  8. 每天一个linux命令(27)--tar命令

    通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候 tar 命令就是必不可少的一个功能强大的工具.Linux 中最流行的 tar 是麻雀虽小,五脏俱全. tar 命令可以为Linux ...

  9. Linux命令:tar命令批量解压方法总结

    tar命令批量解压方法总结 (2010-05-24 17:48:46) 转载▼ 标签: tar 批量解压 杂谈 分类: linux学习 由于linux的tar命令不支持批量解压,所以很多网友编写了好多 ...

随机推荐

  1. samba 奇怪问题

    有一个centos 7  samba服务器,配置如下: [root@proxy223 20150331]# cat /etc/samba/smb.conf [global] workgroup = W ...

  2. ExtJs--09--javascript对象的方法的3种写法 prototype通过原型设置方法效率最好

    /** * javascript对象的方法的3种写法 推荐第三种 运行效率最好 */ function P(name , age){ this.name = name ; this.age = age ...

  3. C#之插入排序

    算法描述 1.假定数组第一位为有序序列,抽出后一位元素与有序序列中元素依次比较: 2.如果有序序列元素大于抽出元素,将该元素向后移位: 3.重复前面步骤依次抽取无序序列中首位元素进行比较,直到所有数值 ...

  4. VBS调用Windows API函数

    Demon's Blog 忘记了,喜欢一个人的感觉 Demon's Blog  »  程序设计  »  VBS调用Windows API函数 « 用VBS修改Windows用户密码 在VB中创建和使用 ...

  5. ClipboardEvent.clipboardData

    ClipboardEvent.clipboardData https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent/clipboa ...

  6. leecode 题解 || Merge k Sorted Lists 问题

    problem: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its comp ...

  7. [模板] BSGS

    BSGS是一种解决一类专门的问题的解法,主要是解决已知A, B, C,求X使得A^x = B (mod p)这一类问题. 解法很简单,先设x = i*m-j(m=ceil(sqrt(p))),然后进行 ...

  8. LuoguP4462 [CQOI2018]异或序列

    https://zybuluo.com/ysner/note/1124952 题面 给你一个大小为\(n\)的序列,然后给你一个数字\(k\),再给出\(m\)组询问,询问给出一个区间,问这个区间里面 ...

  9. Gym - 101972B Arabella Collegiate Programming Contest (2018) B. Updating the Tree 树DFS

    题面 题意:T组数据,每次给你1e5个点的树(1为根),每个点有一权值,询问1-n每个节点的子树中, 至少修改几个点的权值(每次都可以任意修改),才能让子树中任意2点的距离==他们权值差的绝对值 无解 ...

  10. 微信小程序商品展示页面(仿咸鱼)

    项目中做了一个商品发布展示的页面,记录下来 解决问题: 想在setData中更改数组具体下标中的某个值: let one = "lowMoney[" + 0 + "].m ...