我有一个.tar.gz
文件,其中可能包含以下文件:
folder1/folder2/folder3/imp_folder1/file11.jpg
folder1/folder2/folder3/imp_folder1/file12.jpg
folder1/folder2/folder3/imp_folder2/file21.jpg
folder1/folder2/folder3/imp_folder3/file31.jpg
...
...
我想将其解压到以下目录:
/new_folder1/new_folder2/imp_folder1/file11.jpg
/new_folder1/new_folder2/imp_folder1/file12.jpg
/new_folder1/new_folder2/imp_folder2/file21.jpg
/new_folder1/new_folder2/imp_folder3/file31.jpg
...
...
基本上folder1/folder2/folder3/
应该替换为/new_folder1/new_folder2/
.
由于这将有数百个或数千个文件,那么实现此目的最快的方法是什么?
答案1
您已经在评论中获得了一些可能答案的链接,但我想建议另一种方法。您可以在某个位置创建与原始目录树相同的目录树,并将要替换的路径 ( folder1/folder2/folder3
) 链接到新位置 ( /new_folder1/new_folder2
)。
cd /tmp
mkdir -p folder1/folder2
ln -s /new_folder1/new_folder2 folder1/folder2/folder3
--keep-directory-symlink
然后您可以通过添加标志(自版本 1.27 以来存在)来提取存档。
tar --keep-directory-symlink -zxvf tarball.tar.gz