bash 向上移动目录中的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/628617/
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 All Files From Directories One Step Up
提问by neversaint
I have a directories that look like this
我有一个看起来像这样的目录
fool@brat:/mydir/ucsc_mm8> tar -xvf *.tar
1/chr1.fa.masked
1/chr1_random.fa.masked
2/chr2.fa.masked
3/chr3.fa.masked
4/chr4.fa.masked
5/chr5.fa.masked
5/chr5_random.fa.masked
19/chr19.fa.masked
Un/chrUn_random.fa.masked
What I want to do is to move out all the "*.masked" files in the subdirectories /1upto /Un.
Is there a compact way to do it in Linux/Unix?
我想要做的是将子目录中的所有“*.masked”文件移出/1至/Un. 在 Linux/Unix 中是否有一种紧凑的方法来做到这一点?
回答by bsdfish
The typical way of moving files all files matching a particular expression is
移动与特定表达式匹配的所有文件的典型方法是
mv 1/*.masked targetDir
where targetDir could be ..
targetDir 可能在哪里..
If you want to move it from directories 1,2,3 then you can do something like
如果你想从目录 1,2,3 中移动它,那么你可以做类似的事情
mv */*.masked targetDir
Or, if you want to specifically move it from numbered directories, you can just run something like
或者,如果您想专门从编号目录中移动它,您可以运行类似
mv [0-9][0-9]/*.masked targetDir
回答by Brian Pellin
Many unix shells support the * operator in the directory portion of the path as well. The following works in at least bash and zsh:
许多 unix shell 也支持路径的目录部分中的 * 运算符。以下至少适用于 bash 和 zsh:
ls */*.masked
This will return all of the files that end in .masked one directory deeper.
这将返回以 .masked 更深一层目录结尾的所有文件。
So to move them:
所以要移动它们:
mv */*.masked destination
回答by vladr
mv */*.masked .

