[英]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.