前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tar命令中的 -C 作用

tar命令中的 -C 作用

作者头像
拓荒者
发布2019-06-22 14:17:00
5300
发布2019-06-22 14:17:00
举报
文章被收录于专栏:运维经验分享运维经验分享

为什么80%的码农都做不了架构师?>>>

tar命令中的 -C 作用

我用这个命令:tar zcvf chao.tar.gz /chao/*  打包文件的时候,在压缩包里把  /chao/这个路径也打包进去了。

复制代码
复制代码
代码语言:javascript
复制
[root@yunwei-test chao]# ls /chao/
01.txt  02.txt  03.txt  04.txt  05.txt  06.txt  07.txt  08.txt  09.txt  10.txt

[root@yunwei-test chao]# tar zcvf /tar/chao.tar.gz /chao/*
tar: Removing leading `/' from member names
/chao/01.txt
/chao/02.txt
/chao/03.txt
/chao/04.txt
/chao/05.txt
/chao/06.txt
/chao/07.txt
/chao/08.txt
/chao/09.txt
/chao/10.txt

[root@yunwei-test chao]# ls /tar/
chao.tar.gz

#解压
[root@yunwei-test chao]# cd /tar/
[root@yunwei-test tar]# ls
chao.tar.gz
[root@yunwei-test tar]# tar xf chao.tar.gz 
[root@yunwei-test tar]# ls
chao  chao.tar.gz
[root@yunwei-test tar]# cd chao/
[root@yunwei-test chao]# ls
01.txt  02.txt  03.txt  04.txt  05.txt  06.txt  07.txt  08.txt  09.txt  10.txt
复制代码
复制代码

我想不要路径,我不想切换目录过去,而又只想打包指定目录下的文件。 使用 -C 参数。 

复制代码
复制代码
代码语言:javascript
复制
##打包
[root@yunwei-test chao]# tar zcvf /tar/chao.tar.gz  -C /chao .
./
./01.txt
./02.txt
./03.txt
./04.txt
./05.txt
./06.txt
./07.txt
./08.txt
./09.txt
./10.txt

[root@yunwei-test chao]# ls /tar/
chao.tar.gz
[root@yunwei-test chao]# cd /tar/
[root@yunwei-test tar]# ls
chao.tar.gz

#解压
[root@yunwei-test tar]# tar xvf chao.tar.gz 
./
./01.txt
./02.txt
./03.txt
./04.txt
./05.txt
./06.txt
./07.txt
./08.txt
./09.txt
./10.txt
[root@yunwei-test tar]# ls
01.txt  02.txt  03.txt  04.txt  05.txt  06.txt  07.txt  08.txt  09.txt  10.txt  chao.tar.gz
复制代码
复制代码

 ##在解压的时候 -C 是解压到指定目录中。

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • tar命令中的 -C 作用
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档