Linux

使用 tar 從文件夾中壓縮特定文件夾(目錄)

  • August 30, 2018

我正在嘗試使用tar將子目錄壓縮/root/folder/folder{1..5}到單個壓縮存檔test1.tar.bz2中。我正在使用以下命令:

tar -cvjf test1.tar.bz2 root/folder/folder{1..5}

不幸的是,這不起作用,我得到以下輸出:

tar: root/folder/folder1: Cannot stat: No such file or directory
tar: root/folder/folder2: Cannot stat: No such file or directory
tar: root/folder/folder3: Cannot stat: No such file or directory
tar: root/folder/folder4: Cannot stat: No such file or directory
tar: root/folder/folder5: Cannot stat: No such file or directory
tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

您使用的是相對路徑而不是絕對路徑。

改變:

root/folder/folder{1..5}

太(正確的絕對路徑):

/root/folder/folder{1..5}

或(正確的相對路徑):

folder/folder{1..5}

解釋:

您位於根主目錄 ( /root) 中,因此相對路徑將為/root+ relative_path,因此在您的情況下,您提供tar的路徑/root/root/folder/folder{1..5}不存在。您可以提供正確的相對路徑(省略root/開頭的 )或提供絕對路徑。

引用自:https://unix.stackexchange.com/questions/465735