我用这个命令:tar zcvf chao.tar.gz /chao/* 打包文件的时候,在压缩包里把 /chao/这个路径也打包进去了。
1[root@yunwei-test chao]# ls /chao/ 201.txt 02.txt 03.txt 04.txt 05.txt 06.txt 07.txt 08.txt 09.txt 10.txt 3 4[root@yunwei-test chao]# tar zcvf /tar/chao.tar.gz /chao/* 5tar: Removing leading `/' from member names 6/chao/01.txt 7/chao/02.txt 8/chao/03.txt 9/chao/04.txt 10/chao/05.txt 11/chao/06.txt 12/chao/07.txt 13/chao/08.txt 14/chao/09.txt 15/chao/10.txt 16 17[root@yunwei-test chao]# ls /tar/ 18chao.tar.gz 19 20#解压 21[root@yunwei-test chao]# cd /tar/ 22[root@yunwei-test tar]# ls 23chao.tar.gz 24[root@yunwei-test tar]# tar xf chao.tar.gz 25[root@yunwei-test tar]# ls 26chao chao.tar.gz 27[root@yunwei-test tar]# cd chao/ 28[root@yunwei-test chao]# ls 2901.txt 02.txt 03.txt 04.txt 05.txt 06.txt 07.txt 08.txt 09.txt 10.txt
我想不要路径,我不想切换目录过去,而又只想打包指定目录下的文件。 使用 -C 参数。
1##打包[root@yunwei-test chao]# tar zcvf /tar/chao.tar.gz -C /chao . 2./ 3./01.txt 4./02.txt 5./03.txt 6./04.txt 7./05.txt 8./06.txt 9./07.txt 10./08.txt 11./09.txt 12./10.txt 13 14[root@yunwei-test chao]# ls /tar/ 15chao.tar.gz 16[root@yunwei-test chao]# cd /tar/ 17[root@yunwei-test tar]# ls 18chao.tar.gz#解压 19[root@yunwei-test tar]# tar xvf chao.tar.gz 20./ 21./01.txt 22./02.txt 23./03.txt 24./04.txt 25./05.txt 26./06.txt 27./07.txt 28./08.txt 29./09.txt 30./10.txt 31[root@yunwei-test tar]# ls 3201.txt 02.txt 03.txt 04.txt 05.txt 06.txt 07.txt 08.txt 09.txt 10.txt chao.tar.gz
##在解压的时候 -C 是解压到指定目录中。