File 将多个目录中相同类型的所有文件向上移动到一个文件夹中

File 将多个目录中相同类型的所有文件向上移动到一个文件夹中,file,unix,command-line,File,Unix,Command Line,我在一个文件夹中有大约2000个子文件夹,每个文件夹中都有.pdf文件。我需要一个unix命令将所有这些文件移到一个文件夹中 $ cd thefolder # which contains the subfolders and where the PDFs should land $ find . -name *.pdf | xargs -I {} cp -iv {} . # find all files # which end in .pdf # recursively from # the

我在一个文件夹中有大约2000个子文件夹,每个文件夹中都有
.pdf
文件。我需要一个unix命令将所有这些文件移到一个文件夹中

$ cd thefolder # which contains the subfolders and where the PDFs should land
$ find . -name *.pdf | xargs -I {} cp -iv {} .

# find all files
# which end in .pdf
# recursively from
# the current folder
#                    |
#                      for each emitted line
#                      copy the output (captured by {}) to 
#                      the specified path ('.' is the current directory)
#                      copy should be verbose and should ask,
#                      in case a file would be overwritten

这会将您的文件复制到
/thefolder/
中。如果要移动它们,请将
cp
替换为
mv

谢谢,但我需要知道这肯定会起作用,我不能丢失/放错这些文件,而且我在这方面没有太多的知识…如果我进入每个子文件夹并运行命令,这会起作用,但我正在寻找可以在每个子目录中查找的内容,然后将文件向上移动,我不必在每个文件夹中多次运行命令。@sassy_geekette:
是一个管道,通过输入和输出连接两个程序。所以要进行测试,只需执行
find-单独命名*.pdf
(不会复制或移动任何内容)。如果这与您感兴趣的文件匹配,请执行以下操作:
find-name*.pdf | xargs-I{}echo{}
。输出应该是相同的。不过,这不会移动或复制任何内容。然后是
cp
mv