2

我创建了以下脚本,将定义的旧文件从源目录移动到目标目录。它运行良好。

#!/bin/bash

echo "Enter Your Source Directory"
read soure

echo "Enter Your Destination Directory"
read destination 

echo "Enter Days"
read days



 find "$soure" -type f -mtime "-$days" -exec mv {} "$destination" \;

  echo "Files which were $days Days old moved from $soure to $destination"

这个脚本很好地移动了文件,但它也移动了我不想要的源子目录的文件。它不应该占用子目录文件。我怎样才能做到这一点 ?

4

1 回答 1

4

添加-maxdepth 1到您的find命令中,使其不会进入子目录。

find手册页:

-maxdepth levels
    Descend  at  most  levels (a non-negative integer) levels of directories below the command line arguments.
于 2012-12-21T15:56:29.930 回答