【问题标题】:error to delete files older than 1 day from csv list从 csv 列表中删除超过 1 天的文件时出错
【发布时间】:2015-04-06 20:13:39
【问题描述】:

如果目录中的文件早于 1 天,我想从耗材 csv 文件中删除它。

我尝试打印它们以进行测试:

in.txt

1,one
2,two

代码:

 INPUT="in.txt"
 while IFS=',' read -r id name
 do
   find tmp/$name -mtime +1 -type f
 done < "$INPUT"

此代码抛出错误:

find: bad status-- tmp/one
find: bad status-- tmp/two

谢谢。

【问题讨论】:

  • 试试find tmp -name $name -mtime ... 祝你好运。

标签: sh ksh aix


【解决方案1】:

回想一下find 命令的格式是

 find ${baseDir} -${options ......} args to opts.

你的表格在说

find tmp/$name -mtime +1 -type f
# --^^^^^^^^^^ -- start looking in dir tmp/$name

你可能想说

find tmp -name $name -mtime +1 -type f
#---^^^^^ start looking in the tmp dir

可能不需要保留-type f,但它会阻止您匹配目录而不是文件。

IHTH。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 2017-09-30
    • 2016-09-20
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多