CP:复制从所有子目录一定的扩展名的文件 [英] cp: copy all files with a certain extension from all subdirectories
问题描述
在Unix下,我想所有的文件复制具有一定的扩展名(所有Excel文件),从所有子目录到另一个目录。我有以下命令:
Under unix, I want to copy all files with a certain extension (all excel files) from all subdirectories to another directory. I have the following command:
cp --parents `find -name \*.xls*` /target_directory/
这个命令的问题是:
The problems with this command are:
-
拷贝它的目录结构,以及,我只希望这些文件(这样所有文件应在/目标目录结束/)
It copies the directory structure as well, and I only want the files (so all files should end up in /target_directory/)
它不会复制名带有空格的文件(这是不少)
It does not copy files with spaces in the filenames (which are quite a few)
有关这些问题的解决方案,任何?非常感谢!
Any solutions for these problems? Many thanks!!
推荐答案
- 父母
正在复制的目录结构,所以你应该摆脱那个
--parents
is copying the directory structure, so you should get rid of that.
您已经写了这个问题的方法,在找到
执行,并将输出放置到命令行,这样 CP
不能在空格分隔的文件名进行区分,并且在空间内<的EM>的文件名。这是更好地做这样的事情。
The way you've written this, the find
executes, and the output is put onto the command line such that cp
can't distinguish between the spaces separating the filenames, and the spaces within the filename. It's better to do something like
$ find . -name \*.xls -exec cp {} newDir \;
在 CP
是每个文件名查找执行
查找,并通过正确的文件名。 下面是关于此技术的更多信息的。
in which cp
is executed for each filename that find
finds, and passed the filename correctly. Here's more info on this technique.
而不是所有上述情况,你可以使用的zsh 并只需键入
Instead of all the above, you could use zsh and simply type
$ cp **/*.xls target_directory
的zsh
可扩展通配符包含子目录,使这样的事情很容易。
zsh
can expand wildcards to include subdirectories and makes this sort of thing very easy.
这篇关于CP:复制从所有子目录一定的扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!