bash 如何移动目录中具有特定前缀的所有文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12701044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to move all files in a directory that have a specific prefix?
提问by Hugo Gon?alves
I'm creating an shscript file to move files from a folder to another, but only move files starting with system@.
我正在创建一个sh脚本文件来将文件从一个文件夹移动到另一个文件夹,但只移动以system@.
So how can I move only the files that start with system@?
那么我怎样才能只移动以 开头的文件system@呢?
#pseudo-code
foreach file "system@*.*" in dir
move to /.../...
Thanks in advance.
提前致谢。
回答by Kevin
You should really look at a bash reference before you post a question like this.
在发布这样的问题之前,您真的应该查看 bash 参考。
for file in dir/system@*; do
mv "$file" /path/to/destination
done
Apparently I'm more tired than I thought. 3coins' commentis even better:
显然我比我想象的更累。3coins的评论更好:
mv dir/system@* /path/to/destination
Assuming you don't have enough matching files to exceed the maximum command line length.
假设您没有足够的匹配文件来超过最大命令行长度。

