gpt4 book ai didi

循环错误的Linux shell脚本

转载 作者:可可西里 更新时间:2023-11-01 11:45:31 25 4
gpt4 key购买 nike

我正在尝试创建一个 for 循环来删除超过 15 天的日志文件。下面是我的脚本:

#!/bin/sh
path="/home/test"

logpath="$path/logs"
for logfile in `find $logpath -mtime +14 -type f -name *.log`
do
echo "Deleting Log File: " $logfile
rm -rf $logfile
done

一直报错:

find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

有什么想法吗?

最佳答案

请试试这个 - 添加单引号

#!/bin/sh
path="/home/test"

logpath="$path/logs"
for logfile in `find $logpath -mtime +14 -type f -name '*.log'`
do
echo "Deleting Log File: " $logfile
rm -rf $logfile
done

关于循环错误的Linux shell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38694016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com