linux - 仅当文件存在于 shell 脚本中时才移动

标签 linux sh mv

我想使用 mv 重命名一个文件:

mv src.txt dest.txt

如果文件不存在,我得到一个错误:

mv: cannot stat ‘src.txt’: No such file or directory

如何仅在文件已存在时才使用 mv

我不想将 stderr 重定向到 dev/null 因为我想保留发生的任何其他错误

最佳答案

一行:

[ -f old ] && mv old nu

关于linux - 仅当文件存在于 shell 脚本中时才移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33414768/

相关文章:

c - 实现动态内存管理功能

c - i7 CPU 860 @ 2.80GHz 是否包含 L2?

linux - 如何在 Linux 的目录中找到所有不可执行的文件?

posix - 如何检查标准输入是来自终端还是shell脚本中的管道?

mv: "Directory not Empty"- 如何将目录与 `mv` 合并?

php - MediaWiki 安全 : Alternate file ayout

c++ - 优化应用程序内存使用

linux - Bash 脚本以获取具有所需扩展名的所有文件

linux - 在Linux命令行上将文件移动到匹配的文件夹中

linux - 移动除指定文件夹之外的所有文件