如何在不包括目录本身的情况下对文件和文件夹的目录进行 tar? [英] How do I tar a directory of files and folders without including the directory itself?
本文介绍了如何在不包括目录本身的情况下对文件和文件夹的目录进行 tar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通常这样做:
tar -czvf my_directory.tar.gz my_directory
如果我只想在 my_directory 中包含所有内容(包括任何隐藏的系统文件),而不是目录本身,该怎么办?我不要:
What if I just want to include everything (including any hidden system files) in my_directory, but not the directory itself? I don't want:
my_directory
--- my_file
--- my_file
--- my_file
我想要:
my_file
my_file
my_file
推荐答案
cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd -
应该在一行中完成这项工作.它也适用于隐藏文件.*"至少在 bash 中不会通过路径名扩展来扩展隐藏文件.下面是我的实验:
should do the job in one line. It works well for hidden files as well. "*" doesn't expand hidden files by path name expansion at least in bash. Below is my experiment:
$ mkdir my_directory
$ touch my_directory/file1
$ touch my_directory/file2
$ touch my_directory/.hiddenfile1
$ touch my_directory/.hiddenfile2
$ cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd ..
./
./file1
./file2
./.hiddenfile1
./.hiddenfile2
$ tar ztf my_dir.tgz
./
./file1
./file2
./.hiddenfile1
./.hiddenfile2
这篇关于如何在不包括目录本身的情况下对文件和文件夹的目录进行 tar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文