Linux

如何壓縮shell腳本文件中的文件?

  • October 22, 2016

我在終端中看到了一個 .sh 文件,它在 sh 文件中提取了一些 jar 文件,如何創建這樣的 sh 文件?我無法在普通 gedit 中打開該 sh 文件來檢查內容。有沒有辦法做到這一點?

s用於 Shell 檔案

使用shar實用程序創建 shell 檔案。例如:

# Create some fixture data to archive.
cd /tmp
mkdir -p foo/bar/baz
touch foo/bar/baz/quux

# Create the shell archive.
find foo/ -exec shar {} + > quux.sh

# Remove fixture data.
rm -rf foo/

# Extract archive to recreate directories and files.
sh quux.sh

您可以使用 驗證這是否重新創建了您的數據ls -R foo。此外,如果您檢查quux.sh,您會發現它由一系列簡單的 shell 命令組成。如果需要,您可以將這些命令直接插入到另一個 shell 腳本中,或者從另一個腳本呼叫存檔來解壓縮它。

注意事項

macOS 上的 BSD 版本的shar在沒有單獨的編碼步驟的情況下無法處理二進制數據,而 GNU 版本有各種可用的編碼選項。如果您的 shar 版本不處理二進制編碼,則最好使用更強大的歸檔選項,例如tar。你的旅費可能會改變。

引用自:https://serverfault.com/questions/809452