1. 程式人生 > >tar命令中的 -C 作用

tar命令中的 -C 作用

tar命令中的 -C 作用

 

我用這個命令:tar zcvf chao.tar.gz /chao/*  打包檔案的時候,在壓縮包裡把  /chao/這個路徑也打包進去了。

複製程式碼

[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 引數。 

複製程式碼

##打包
[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 是解壓到指定