我想压缩一个目录,它看起来像这样:
dir
└── workspace
└── node_modules
└── subfolder
└── workspace
└── node_modules
└── other_folder
我想要排除所有名为node_modules
的文件夹,以及顶层名为workspace
的文件夹,但不包括名为workspace
的子文件夹。
所以,我最终想要的是这样:
dir
└── subfolder
└── workspace
└── other_folder
我正在运行这个命令:
tar -czf ./output.tar.gz --exclude=node_modules --exclude=./workspace dir/.
但它会删除所有名为workspace和node_modules的文件夹,因此最终结果如下:dir
└── subfolder
└── other_folder
如何只删除我想要的特定工作区文件夹,而不是所有相同名称的文件夹?
find
创建要压缩的文件列表。然后将此列表传递给tar,最好使用xargs -0
或类似方法。 - KamilCuk