bash 将文件移动到目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/776202/
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
Moving files to a directory
提问by aatifh
I want to move all files matching a certain patternin the current directory to another directory.
我想将当前目录中匹配特定模式的所有文件移动到另一个目录。
For example, how would I move all the files starting with nzto a directory called foobar? I tried using mvfor that, but it didn't work out well.
例如,我如何将所有以 开头的文件移动nz到名为foobar? 我尝试使用mv它,但效果不佳。
回答by B.E.
find . | grep "your_pattern" | xargs mv destination_directory
Does the following:
执行以下操作:
- Finds all files in the current directory
- Filters them according to your pattern
- Moves all resulting files to the destination directory
- 查找当前目录下的所有文件
- 根据您的模式过滤它们
- 将所有结果文件移动到目标目录
回答by Joey
mv nz* foobarshould do it.
mv nz* foobar应该这样做。
回答by Dikla
mv nz* foobar/
mv nz* foobar/
回答by jso1919
mv nz* foobar/
mv nz* foobar/
- mv- will move or rename file
- nz- will get all the items that start with the "nz"
- foobar/- is the directory where all items will go into
- mv- 将移动或重命名文件
- nz- 将获得所有以“nz”开头的项目
- foobar/- 是所有项目将进入的目录
回答by Oliver Michels
Try to use "mmv", which is installed on most Linux distros.
尝试使用“mmv”,它安装在大多数 Linux 发行版上。
回答by RobS
This will do it, though if you have any directories beginning with nz it will move those too.
这将做到这一点,但如果您有任何以 nz 开头的目录,它也会移动这些目录。
for files in nz*
do
mv $files foobar
done
Edit: As shown above this totally over the top. However, for more complex pattern matches you might do something like:
编辑:如上所示,这完全超出了顶部。但是,对于更复杂的模式匹配,您可能会执行以下操作:
for files in `ls | grep [regexp]`
do
mv $files foobar
done

