文件管理--打包及压缩 tar的用法

一、简介
tar命令是Unix/Linux系统中备份文件的可靠方法,几乎可以工作于任何环境中,它的使用权限是所有用户。建议针对目录
二、压缩:语法tar 选项 压缩包名称 源文件
[root@localhost ~]# tar -cf etc.tar /etc
[root@localhost ~]# tar -czvf etc-gzip.tar.gz /etc/
[root@localhost ~]# tar -cjf etc-bzip.tar.bz /etc/
[root@localhost ~]# tar -cJf etc-xzip.tar.xz /etc/

[root@localhost ~]# tar -cvf  home.tar  /home     //打包
tar: 从成员名中删除开头的“/”
/home/
/home/yonghu/
/home/yonghu/.mozilla/
/home/yonghu/.mozilla/extensions/
/home/yonghu/.mozilla/plugins/
/home/yonghu/.bash_logout
/home/yonghu/.bash_profile
/home/yonghu/.bashrc
/home/1.txt
/home/file2-h2
/home/file222-1
[root@localhost ~]# ls 
anaconda-ks.cfg  **home.tar**                                     公共
asd.ttx          initial-setup-ks.cfg                         模板
bbb              installer                                    视频
etc                                       图片
etc-bzip.tar.bz                                文档
etc-gzip.tar.gz  metasploit-latest-linux-x64-installer.run    下载
etc.tar          metasploit-latest-linux-x64-installer.run.1  音乐
etc-xzip.tar.xz  msfinstall 
[root@localhost ~]# tar  -xf  home.tar       //解压
[root@localhost ~]# ls        //查看               
anaconda-ks.cfg       **home**                             pub
asd.ttx          home.tar                                     公共
bbb              initial-setup-ks.cfg                         模板
etc              installer                                    视频
etc-bzip.tar.bz                            图片
etc-gzip.tar.gz                               文档
etc.tar          metasploit-latest-linux-x64-installer.run    下载
etc-xzip.tar.xz  metasploit-latest-linux-x64-installer.run.1  音乐
file2            msfinstall                                   桌面

三、解压
查看压缩文件:tar -tf +压缩包名
解压:tar -xf +压缩包名
解压:tar -xf +压缩包名 -C +指定存放目录
1.解压gzip压缩包

[root@localhost ~]# ls
anaconda-ks.cfg       installer                                    模板
asd.ttx                       bbb                                         视频           
etc-bzip.tar.bz       metasploit-latest-linux-x64-installer.run    文档
**etc-gzip.tar.gz**       metasploit-latest-linux-x64-installer.run.1  下载
etc-xzip.tar.xz       msfinstall                                   音乐
file2                 pub                                          桌面
initial-setup-ks.cfg  公共
[root@localhost ~]# tar -xf etc-gzip.tar.gz      //解压
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg                         公共
asd.ttx          installer                                    模板
bbb                **etc**                                    视频
 图片                   
etc-bzip.tar.bz  metasploit-latest-linux-x64-installer.run    文档
etc-gzip.tar.gz  metasploit-latest-linux-x64-installer.run.1  下载
etc-xzip.tar.xz  msfinstall                                   音乐
file2            pub                                          桌面

2.解压文件指定存放·

[root@localhost ~]# tar xf  etc-bzip.tar.bz    -C   /root/bbb
[root@localhost ~]# ls   /root/bbb
apps  etc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值