linux - MV : cannot stat error : No such file or directory error

标签 linux bash stat

我需要将一个目录的文件移动到另一个目录。当我使用以下程序时出现统计错误。

for i in dir1/*.txt_dir; do
mv $i/*.txt  dir2/`basename $i`.txt
done

错误信息

mv: cannot stat `dir1/aa7.txt_dir/*.txt': No such file or directory

最佳答案

通常,当一个不匹配任何文件名的 glob 被扩展时,它保持不变。因此,您会得到如下结果:

$ rm .bak rm: 无法删除 `.bak': 没有那个文件或目录

为避免这种情况,我们需要更改 nullglob 变量的默认值。

    #BASH

    shopt -s nullglob

    for i in dir1/*.txt_dir; do
       mv $i/*.txt  dir2/'basename $i'.txt
    done

在这里阅读更多相关信息:http://mywiki.wooledge.org/NullGlob

希望这对您有所帮助!

关于linux - MV : cannot stat error : No such file or directory error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12729784/

相关文章:

linux - 在 bash 别名中转义字符

c - MINIX内部碎片2

C - Linux 稀疏文件 : How to check if file is sparse and print 0-filled disk blocks

c - 在 C 中读取目录时出现问题

linux - 如何调试我的 Cron 作业运行两次的原因?

linux - 在 Linux 内核模块中获取屏幕亮度

linux - 如何使用可启动 USB 在 Toshiba Satellite 中删除以前版本的 centos 7 并安装新的 centos 7

c - 在 mmap 中执行代码以产生可执行代码段错误

bash - 如何从 [windows 路径] 设置 [Windows 上 Ubuntu 上的 Bash] [环境变量]?

linux - Centos 5 中的 Poodle 漏洞