
此Shell脚本的文件名为: clearFile.sh. 内容是:

#! /bin/bash
function clearFile(){
if [`$1 -eq 'logs'` -o `$1 -eq 'log'`]; then
echo "clearFile can be called"
for file in `ls $1`
do
if [ -d $1"/"$file ]; then
echo "deleting directory: " $1"/"$file
rm -rf $1"/"$file
else
echo "deleting file: " $1"/"$file
rm -rf $1"/"$file
fi
done
else
echo "clearFile cannot be called!!!, the dir name is: "$1
fi
}
runPath=$(cd `dirname $0`;pwd)
echo "the script is located in directory :" $runPath
clearFile $1

将shell脚本复制到centos中的指定目录后,使用以下命令授予可执行权限:

chmod 777 clearFile.sh

然后,如果要删除logs目录中的所有日志文件,则可以愉快地使用它. 只需执行以下命令:
./clearFile.sh logs
但是shell脚本删除文件,出于安全原因shell脚本删除文件,允许清除内容的文件夹的名称只能是log或log,也就是说,它仅对以下两个调用有效. 如有必要,您可以自己对其进行修改.
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/sanxing/article-227870-1.html
都是从资本市场中成为顶级的富豪的
跟谁打也不要跟英美打