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

时间:2010-09-10 17:36:31

标签: file unix command-line

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

1 个答案:

答案 0 :(得分:10)

$ 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