main_directory/
directory1:
sub_directory1:
files:
myfile.txt
otherfile.txt
sub_directory2:
files:
myfile.txt
otherfile.txt
sub_directory3:
files:
myfile.txt
otherfile.txt
sub_directory4:
files:
myfile.txt
otherfile.txt
directory2:
sub_directory1:
files:
myfile.txt
otherfile.txt
sub_directory2:
files:
myfile.txt
otherfile.txt
sub_directory3:
files:
myfile.txt
otherfile.txt
sub_directory4:
files:
myfile.txt
otherfile.txt
我试图找出(通过反复试验,因为我不是Linux的专家)如何只在所有目录中gzip myfile.txt文件.由于它们在不同的路径中都具有相同的文件名(没有办法解决这个问题),我需要能够将文件路径保存在存档中.所以我想要创建的最终gzipped tar文件将包含以下内容:
mytar.tar.gz
main_directory/directory1/sub_directory1/files/myfile.txt
main_directory/directory1/sub_directory2/files/myfile.txt
main_directory/directory1/sub_directory3/files/myfile.txt
main_directory/directory1/sub_directory4/files/myfile.txt
main_directory/directory2/sub_directory1/files/myfile.txt
main_directory/directory3/sub_directory2/files/myfile.txt
main_directory/directory4/sub_directory3/files/myfile.txt
main_directory/directory5/sub_directory4/files/myfile.txt
有一个简单的bash方式来做到这一点?我想我可以写一个python脚本来做它,但这似乎有点过分.
有人有建议吗?
解决方法:
这克服了另一个答案中描述的这个问题.
find main_directory/ -name "myfile.txt" | tar -czvf mytar.tar.gz -T -
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。