简体   繁体   English

mv:无法统计错误:没有此类文件或目录错误

[英]mv: cannot stat error : No such file or directory error

I need to move the files of a directory to another directory.I get stat error when I used the following program.我需要将一个目录的文件移动到另一个目录。当我使用以下程序时出现 stat 错误。

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

error message错误信息

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

Normally, when a glob which does not match any filenames is expanded, it remains unchanged.通常,当一个不匹配任何文件名的 glob 被扩展时,它保持不变。 Thus, you get results like this:因此,您会得到如下结果:

$ rm .bak rm: cannot remove ` .bak': No such file or directory $ rm .bak rm: 无法删除 ` .bak': 没有那个文件或目录

To avoid this we need to change the default value of nullglob variable.为了避免这种情况,我们需要更改 nullglob 变量的默认值。

    #BASH

    shopt -s nullglob

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

Read more about it here: http://mywiki.wooledge.org/NullGlob在此处阅读更多相关信息: http : //mywiki.wooledge.org/NullGlob

Hope this helps!希望这可以帮助!

mv $i/*.txt  dir2/`basename $i`.txt

This doesn't work when there are no text files in $i/ .$i/中没有文本文件时,这不起作用。 The shell passes the raw string "$i/*.txt" to mv with the unexpanded * in it, which mv chokes on. shell 将原始字符串"$i/*.txt"传递给mv其中包含未扩展的*mv阻塞。

Try something like this:尝试这样的事情:

for i in dir1/*.txt_dir; do
    find $i -name '*.txt' -exec mv {} dir2/`basename $i`.txt \;
done

when you put directory/* alone in for iteration, it list each file with absolute path.当您单独放置 directory/* 进行迭代时,它会列出每个文件的绝对路径。 use `ls使用`ls

for i in ls dir1/*.txt_dir ;对于我在ls dir1/*.txt_dir ; do

Whilst it is not shown in your example - using the correct quotes is important.虽然它没有在您的示例中显示 - 使用正确的引号很重要。 in BASH "*" evaluates to * and '*' evaluates to the expansion glob.在 BASH 中,"*" 的计算结果为 *,而 '*' 的计算结果为扩展全局。 so所以

`ls *`

will show all files in directory and将显示目录中的所有文件和

`ls "*"`

will show all files named the literal *将显示所有名为文字 * 的文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mv命令移动文件但报告错误:无法统计没有这样的文件或目录 - mv command moves file but reports error: cannot stat no such file or directory mv:无法统计“coverage.txt”:没有这样的文件或目录 - mv: cannot stat 'coverage.txt': No such file or directory Doxygen make make install错误:无法统计“示例”:没有这样的文件或目录 - Doxygen make make install Error : cannot stat ‘examples’: No such file or directory 错误:stat:C编程中没有这样的文件或目录,opendir()和stat() - ERROR: stat: No Such File Or Directory, opendir() and stat() in C programming 错误:md5sum:stat '>':没有那个文件或目录 - Error: md5sum: stat '>': No such file or directory 文本文件中的单引号完整路径文件不能用于循环处理 mv: cannot stat ... No such file or directory - Single quoted full path files in a text file can't do for loop processing mv: cannot stat … No such file or directory 使用cp将.html文件转换为.txt。 错误:cp:无法统计“ /*.html”:没有此类文件或目录 - Convert .html file to .txt using cp | error: cp: cannot stat '/*.html': No such file or directory cp:无法统计…没有此类文件或目录 - cp: cannot stat … No such file or directory cp: cannot stat No such file or directory - cp: cannot stat No such file or directory Shell cp:无法统计没有这样的文件或目录 - Shell cp: cannot stat no such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM