我需要做一些测试,因为我想在我的 Unix 服务器(Redhat Linux 6.9(64 位))的 Dev 实例中创建一个临时目录,并将文件复制到我想要执行测试的目录中。
以下脚本应执行您所描述的操作:
#! /bin/bash
read -p 'enter name of new folder: ' dir
if [ -e "$dir" ]; then
echo 'A folder with the specified name already exists. Choose a different name.'
else
mkdir "$dir"
while read -r ; do
mystring="${REPLY:2}"
mystring="$(sed 's/\//_/g' <<<"$mystring")"
cp "$REPLY" "$dir/$mystring"
done < <(find / -mtime +30 -name '*.log' -type f)
fi
您可以根据find
需要调整底部的命令:
+30
表示超过 30 天的文件和 /
指定要用于搜索日志文件的搜索目录。 在这里,我假设您想在根目录中搜索日志文件/
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句