bash脚本改进

bash脚本改进,bash,Bash,我已经创建了下面的脚本,它将旧的日期文件从源目录移动到目标目录。它工作得很好 #!/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 {} "$destinat

我已经创建了下面的脚本,它将旧的日期文件从源目录移动到目标目录。它工作得很好

#!/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"
这个脚本可以很好地移动文件,但它也可以移动源子目录中的文件,这是我不想要的。
它不应该接受子目录文件。如何执行此操作?

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

查找
手册页:

-maxdepth levels
    Descend  at  most  levels (a non-negative integer) levels of directories below the command line arguments.

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

查找
手册页:

-maxdepth levels
    Descend  at  most  levels (a non-negative integer) levels of directories below the command line arguments.

我的find命令应该查找-maxdepth 1“$soure”-键入f-mtime“-$days”-exec mv{}“$destination”\;或者某件事???不工作会导致以下错误查找:警告:您在非选项参数-type之后指定了-maxdepth选项,但选项不是位置性的(-maxdepth影响在它之前指定的测试以及在它之后指定的测试)。请在其他参数之前指定选项。请尝试:
find“$soure”-maxdepth 1-type f-mtime”-$days”-exec mv{}“$destination”\我的查找命令应该查找-maxdepth 1“$soure”-键入f-mtime“-$days”-exec mv{}“$destination”\;或者某件事???不工作会导致以下错误查找:警告:您在非选项参数-type之后指定了-maxdepth选项,但选项不是位置性的(-maxdepth影响在它之前指定的测试以及在它之后指定的测试)。请在其他参数之前指定选项。请尝试:
find“$soure”-maxdepth 1-type f-mtime”-$days”-exec mv{}“$destination”\