0

我是 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 -mtime -$days -exec mv {} $destination \;
echo "Files which were $days Days old moved from $soure to $destination"

我可以移动文件,但它也保留了我不想要的特定要求的目录结构。

4

2 回答 2

0

可能是您的文件名包含空格,那么该mv命令将是错误的。试试这个。

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

更多的建议可能是使用 identifiers $1$2$3不是这个read替代方案,因为它更容易与 tab 完成一起使用。

于 2012-12-20T12:41:43.333 回答
0

添加-type f以确保您只移动文件,而不是目录

find "$shore" -type f -mtime -$days -exec mv "{}" "$destination" \;
于 2012-12-20T14:38:52.250 回答