首页 > 解决方案 > 将 find & exec 的输出重定向到日志文件

问题描述

我根据以下参考创建了一个用于移动文件的脚本。我正在尝试捕获从源移动到目标的所有文件活动以及任何不成功的文件。 我尝试将输出输出到日志文件,但操作后日志文件大小为 0。请问有什么建议吗?

参考文档# https://unix.stackexchange.com/questions/59112/preserve-directory-structure-when-moving-files-using-find

下面是代码块

destination=$(cd -- "$destination" && pwd)
cd -- "$source" &&
find . -type f -newermt $startdays -not -newermt $enddays -exec sh -c '
  for x do
    mkdir -p "$0/${x%/*}"
    mv "$x" "$0/$x"
  done
' "$destination" {} + >> output.log

标签: linuxshellunixoutput

解决方案


默认情况下,mv不产生任何输出。如果您希望它产生输出,请尝试mv -v.


推荐阅读