分页: 1 / 1

[问题]求助关于cp命令

发表于 : 2008-06-17 13:33
ffsxsy
我在a文件夹下有26个字文件夹,每个文件夹有很多小文件,总数大概2万多,怎么用命令把这所有的2万个文件复制到一个文件夹b下

发表于 : 2008-06-17 13:38
yaoms
cp -a a/* b/

发表于 : 2008-06-17 13:55
syrano
cp -r a/* b/

Re: [问题]求助关于cp命令

发表于 : 2008-06-17 13:58
BigSnake.NET
ffsxsy 写了:我在a文件夹下有26个字文件夹,每个文件夹有很多小文件,总数大概2万多,怎么用命令把这所有的2万个文件复制到一个文件夹b下
是要打散文件夹吗

就是说 b 下没有 a 下的文件夹结构, 只有文件

Re: [问题]求助关于cp命令

发表于 : 2008-06-17 13:59
yaoms
BigSnake.NET 写了:
ffsxsy 写了:我在a文件夹下有26个字文件夹,每个文件夹有很多小文件,总数大概2万多,怎么用命令把这所有的2万个文件复制到一个文件夹b下
是要打散文件夹吗

就是说 b 下没有 a 下的文件夹结构, 只有文件
打散结构,要考虑同名文件的问题。

Re: [问题]求助关于cp命令

发表于 : 2008-06-17 14:16
ffsxsy
BigSnake.NET 写了:
ffsxsy 写了:我在a文件夹下有26个字文件夹,每个文件夹有很多小文件,总数大概2万多,怎么用命令把这所有的2万个文件复制到一个文件夹b下
是要打散文件夹吗

就是说 b 下没有 a 下的文件夹结构, 只有文件
是这样的

如有同名文件,要一个就够了

Re: [问题]求助关于cp命令

发表于 : 2008-06-17 14:23
BigSnake.NET
ffsxsy 写了:
BigSnake.NET 写了:
ffsxsy 写了:我在a文件夹下有26个字文件夹,每个文件夹有很多小文件,总数大概2万多,怎么用命令把这所有的2万个文件复制到一个文件夹b下
是要打散文件夹吗

就是说 b 下没有 a 下的文件夹结构, 只有文件
是这样的

代码: 全选

cd a && find -type f -exec cp -iv {} ../b/ \;

Re: [问题]求助关于cp命令

发表于 : 2008-06-17 14:25
ffsxsy
BigSnake.NET 写了:
ffsxsy 写了:
BigSnake.NET 写了:
ffsxsy 写了:我在a文件夹下有26个字文件夹,每个文件夹有很多小文件,总数大概2万多,怎么用命令把这所有的2万个文件复制到一个文件夹b下
是要打散文件夹吗

就是说 b 下没有 a 下的文件夹结构, 只有文件
是这样的

代码: 全选

cd a && find -type f -exec cp -iv {} ../b/ \;
能不能解释一下
find -type f -exec cp -iv {} ../b/ \
,看起来好复杂

Re: [问题]求助关于cp命令

发表于 : 2008-06-17 14:37
nihui
ffsxsy 写了:
BigSnake.NET 写了:
ffsxsy 写了:
BigSnake.NET 写了:
ffsxsy 写了:我在a文件夹下有26个字文件夹,每个文件夹有很多小文件,总数大概2万多,怎么用命令把这所有的2万个文件复制到一个文件夹b下
是要打散文件夹吗

就是说 b 下没有 a 下的文件夹结构, 只有文件
是这样的

代码: 全选

cd a && find -type f -exec cp -iv {} ../b/ \;
能不能解释一下
find -type f -exec cp -iv {} ../b/ \
,看起来好复杂

查找类型为文件的文件,然后把找到的文件复制到 b 目录去,进行复制的提示~

发表于 : 2008-06-17 14:39
greco
$ cd a
$ find -type f -> list all file (include path)
$ cp -iv {file} ../b/

-i 提示是否覆盖文件
-v 在复制前印出文件名.

发表于 : 2008-06-17 15:37
ffsxsy
都是牛人!最后一个问题
cd a && find -type f -exec cp -iv {} ../b/ \;
最后边分号前的“\”是什么意思?

发表于 : 2008-06-17 17:58
BigSnake.NET
ffsxsy 写了:都是牛人!最后一个问题
cd a && find -type f -exec cp -iv {} ../b/ \;
最后边分号前的“\”是什么意思?
man find

代码: 全选

       -exec command ;                                                          
              Execute  command;  true  if 0 status is returned.  All following  
              arguments to find are taken to be arguments to the command until  
              an  argument  consisting of `;' is encountered.  The string `{}'  
              is replaced by the current file name being processed  everywhere  
              it occurs in the arguments to the command, not just in arguments  
              where it is alone, as in some versions of find.  Both  of  these  
              constructions might need to be escaped (with a `\') or quoted to  
              protect them from expansion by the shell.  See the EXAMPLES sec-  
              tion  for examples of the use of the `-exec' option.  The speci-  
              fied command is run once for each matched file.  The command  is  
              executed  in  the  starting  directory.    There are unavoidable  
              security problems surrounding  use  of  the  -exec  option;  you  
              should use the -execdir option instead.                
注意有个 ; , 这个 ; 是给 find 的, 所以要转义

相当于 find -type f -exec cp -iv {} ../b/ ";"