找到所有 .sh 文件然后复制到脚本备份

找到所有 .sh 文件然后复制到脚本备份

找到.sh您在 Linux 安装中创建的所有脚本(如果需要,递归搜索 - 不包括现有的备份文件夹)

然后它将它们全部复制到名为 -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"

相关内容