linux tar命令-c的作用,tar命令中的 -C 作用

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

48304ba5e6f9fe08f3fa1abda7d326ab.png

[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

48304ba5e6f9fe08f3fa1abda7d326ab.png

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

48304ba5e6f9fe08f3fa1abda7d326ab.png

##打包

[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

48304ba5e6f9fe08f3fa1abda7d326ab.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值