根据MACOS上的ZSH的某些模式移动文件
我正在尝试根据某种模式移动文件,在下面的情况下,将包含 2018
的所有文件移动到 2018/
文件夹:
mv *2018* 2018/
此命令仅适用于 2017
,现在我得到了
mv:将 2018 重命名为 2018/2018:参数无效
所以我尝试了 zmv
:
autoload -Uz zmv
mv *2018* 2018/
它有效,但对于 2019
或具有相同错误消息的任何其他值不再有效。
我应该如何修复它?或者什么是根据某些正则表达式模式移动文件的更好且简单的方法?
我还安装了oh-my-zsh
I'm trying to move files according to some pattern, in the case below, moving all files containing 2018
to 2018/
folder:
mv *2018* 2018/
This command worked once with 2017
, now then I'm getting
mv: rename 2018 to 2018/2018: Invalid argument
So I tried zmv
:
autoload -Uz zmv
mv *2018* 2018/
It worked, but doesn't work anymore for 2019
or any other value with the same error message.
How should I fix it ? Or what is a better and yet simple way to move files according to some regex pattern ?
I also have oh-my-zsh
installed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
使用
.
glob 限定符(在括号中),通配符模式将仅匹配常规文件。如果没有限定符,源模式将在要移动的项目列表中包含目标目录2018
,并且mv
无法将目录移动到其自身中。当我在我的系统上尝试原始模式
*2018*
时,mv
仍然按照请求移动匹配的文件,然后报告有关目录的错误消息。我怀疑当这似乎起作用时,错误消息只是在其他文本中丢失了。演示
.
glob 限定符:顺便说一句,您问题中的
zmv
示例正在调用mv
,而不是zmv
。另外,zmv
的参数通常需要加引号。您不需要在这里使用zmv
,mv
会完成所需的一切。Try this:
With the
.
glob qualifier (in the parentheses), the wildcard pattern will only match regular files. Without the qualifier, the source pattern will include the destination directory2018
in the list of items to move, andmv
cannot move a directory into itself.When I tried the original pattern
*2018*
on my system,mv
still moved the matching files as requested, and then reported the error message about the directory. I suspect that when this appeared to work, the error message was simply lost in some other text.Demonstrating the
.
glob qualifier:BTW, the
zmv
example in your question is invokingmv
, notzmv
. Also, arguments tozmv
usually need to be quoted. You don't wantzmv
here,mv
will do everything needed.