すべての.shファイルを見つけてコピーします。スクリプトのバックアップ

すべての.shファイルを見つけてコピーします。スクリプトのバックアップ

.shLinuxインストールで生成されたすべてのスクリプトを見つけます(必要に応じて再帰的に検索 - 既存のバックアップフォルダを除く)。

次に、-scriptbackupというフォルダにすべてコピーし、tar gzipファイルとして保存します。

ベストアンサー1

このようなことがうまくいくはずです

directory=$(date +%Y-%m-%d)-scriptbackup
#create if it doesn't exist
mkdir -p "$directory"
#find and copy
#replace "." with the directory
#where you want to search for the files,
#if it isn't the same as the current directory
find . -name '*.sh' -exec cp '{}' "$directory" ';'
tar -cvzf "${directory}.tar.gz" "$directory"

おすすめ記事