如何在不包含目录本身的情况下对文件和文件夹的目录进行压缩?
问题描述:
我通常这样做:
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