tr归档命令(打包)

(虚拟机)

复制真机/etc/的内容到 虚拟机/mnt

复制完成后:

 

  要想更快一点,可以选择打包:

(真机)

[root@bogon mnt]# ls
[root@bogon mnt]# tar cf etc.tar /etc
tar: Removing leading `/' from member names
[root@bogon mnt]# ls
etc.tar
[root@bogon mnt]# tar tf etc.tar
etc/
etc/mtab
etc/fstab
etc/crypttab
etc/dnf/
etc/dnf/modules.d/

打包成为一个etc.tar

(虚拟机)

 可以看到快了很多

解包:

[root@localhost mnt]# rm -fr *
[root@localhost mnt]# scp -r root@172.25.254.111:/mnt/etc.tar /mnt
root@172.25.254.111's password: 
etc.tar                                                                       100%   27MB 112.9MB/s   00:00    
[root@localhost mnt]# ls
etc.tar
[root@localhost mnt]# tar xf etc.tar
[root@localhost mnt]# ls
etc  etc.tar
[root@localhost mnt]# cd etc/
[root@localhost etc]# ls
adjtime                     egl              ksmtuned.conf             PackageKit          setroubleshoot
aliases                     enscript.cfg     ld.so.cache               pam.d               sgml
alsa                        environment      ld.so.conf                papersize           shadow
alternatives                ethertypes       ld.so.conf.d              passwd              shadow-
anaconda                    exports          libaudit.conf             passwd-             shells

可以看到,里面的东西都在,可以进一步加快数据传输

 tar

  • c创建
    f指定文件名称
    x解包
    v显示解包过程
    t查看
    r向归档文件(包)中添加文件
    --get解档指定文件
    --delete删除指定文件
    -C指定解压路径
    -Pdon't remove /

    r   添加文件

  • [root@localhost mnt]# touch westos1111111111
    [root@localhost mnt]# tar rf etc.tar westos1111111111 
    [root@localhost mnt]# tar tf etc.tar 
    etc/
    etc/mtab
    etc/fstab
    etc/crypttab
    etc/dnf/
    etc/dnf/modules.d/
    

    由上图可以看到,文件建立进去了

  • [root@localhost mnt]# rm -fr etc westos1111111111 westos.tar 
    [root@localhost mnt]# ls
    etc.tar
    [root@localhost mnt]# tar xf etc.tar
    [root@localhost mnt]# ls
    etc  etc.tar  westos1111111111
    [root@localhost mnt]# 
    

  • --get  解档指定文件

  • tar f etc.tar --get westos1111111111
  • 删除文件:--delete

  • [root@localhost mnt]# tar f etc.tar --delete westos1111111111
    [root@localhost mnt]# tar tf  etc.tar
    

     解压到指定目录:-C

  • [root@localhost mnt]# tar xf etc.tar -C /opt/
    

     -P

  • [root@localhost mnt]# tar cf etc.tar /etc/
    tar: 从成员名中删除开头的“/”
    
  • 注意,-P慎用,不把绝对路径转为相对路径,而保留绝对路径的名称。如果解时也加P,就会解压到绝对路径下,可能会覆盖原文件内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值