Linux 如何使用cp从不同目录复制多个文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9915822/
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 copy multiple files from a different directory using cp?
提问by ziulfer
I want to copy multiple files from a specific directory once I am in another directory. To clarify I want to do the following, at once (one command):
一旦我在另一个目录中,我想从特定目录复制多个文件。为了澄清我想立即执行以下操作(一个命令):
cp ../dir5/dir4/dir3/dir2/file1 .
cp ../dir5/dir4/dir3/dir2/file2 .
cp ../dir5/dir4/dir3/dir2/file3 .
cp ../dir5/dir4/dir3/dir2/file4 .
I can't use cp ../dir5/dir4/dir3/dir2/* .
because in dir2
there are n
files (n>4)
我不能使用, cp ../dir5/dir4/dir3/dir2/* .
因为dir2
里面有n
文件(n>4)
By the way, I'm using bash
.
顺便说一句,我正在使用bash
.
Thanks.
谢谢。
采纳答案by Philipp
cp ../dir5/dir4/dir3/dir2/file[1234] .
or (in Bash)
或(在 Bash 中)
cp ../dir5/dir4/dir3/dir2/file{1..4} .
If the file names are non-contiguous, you can use
如果文件名不连续,您可以使用
cp ../dir5/dir4/dir3/dir2/{march,april,may} .
回答by zbyszek26104
Try this one:
试试这个:
cp ../dir5/dir4/dir3/dir2/file{1..4}
回答by ghoti
If all the files you want to copy are in the pattern of file{number}{othertext}
, you could use something like:
如果您要复制的所有文件都在 的模式中file{number}{othertext}
,您可以使用以下内容:
cp ../dir5/dir4/dir3/dir2/file[0-9]* .
Note that this will copy file5
, but it will also copy file0abc
.
请注意,这将复制file5
,但它也会复制file0abc
。
If you would like to copy ONLY those four files (and not the {othertext} ones), you can use:
如果您只想复制这四个文件(而不是 {othertext} 文件),您可以使用:
cp ../dir5/dir4/dir3/dir2/file[1-4] .
Note that while this lookslike part of a regular expression, it is not.
请注意,虽然这看起来像是正则表达式的一部分,但实际上并非如此。