linux - mv 'x' 和 'y' 是同一个文件

标签 linux shell unix

我正在尝试编写一个 shell 脚本,将文件从一个目的地移动到另一个目的地,然后删除超过 7 天的文件。

但是,我不断收到同样的错误:

mv: ‘x’ and ‘y’ are the same file

这是我的命令:

find /opt/files/ -type f -name '*.csv' -mtime +1 -exec mv {} /opt/files/oldCSVFiles/ \;
find /opt/files/oldCSVFiles/ -type f -name '*.csv' -mtime +7 -exec rm {} \;

提前致谢!

最佳答案

只需跳过文件夹 /opt/files/oldCSVFiles/ 中的那些文件:

find /opt/files/ -type f -name '*.csv' -mtime +1 -not -path "/opt/files/oldCSVFiles/*" -exec mv {} /opt/files/oldCSVFiles/ \;
find /opt/files/oldCSVFiles/ -type f -name '*.csv' -mtime +7 -exec rm {} \;

关于linux - mv 'x' 和 'y' 是同一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55587747/

相关文章:

c - 如何在 C 中模拟构造函数或静态 block

java - TCP如何在Java中发送/接收实时大数据包?

linux - Linux AMD64 中如何使用 fs/gs 寄存器?

git - cpanel 警告 : Your system administrator must enable shell access to allow you to view clone URLS

linux - Unix shell 脚本错误

bash 外壳;读取命令;在 Windows 7 上使用 Cygwin

c++ - 为什么 reinterpret_cast 不将 'unsigned char' 转换为 'char' ?

linux - 重命名目录和子目录中的所有文件 Linux

shell - 符号链接(symbolic link)不继承权限

python - 我们如何使用 python 从 ssh 代理运行 tmux