【发布时间】:2010-09-10 17:36:31
【问题描述】:
我在一个文件夹中有大约 2000 个子文件夹,每个文件夹中都有 .pdf 文件。我需要一个 unix 命令,它将所有这些文件移到一个文件夹中。
【问题讨论】:
标签: file unix command-line
我在一个文件夹中有大约 2000 个子文件夹,每个文件夹中都有 .pdf 文件。我需要一个 unix 命令,它将所有这些文件移到一个文件夹中。
【问题讨论】:
标签: file unix command-line
$ 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。
【讨论】:
| 是一个管道,通过它们的输入和输出连接两个程序。所以要测试,只需单独执行find . -name *.pdf(这不会复制或移动任何东西)。如果这与您感兴趣的文件匹配,请执行以下操作:find . -name *.pdf | xargs -I {} echo {}。输出应该是一样的。尽管如此,这不会移动或复制任何东西。然后cp 或mv。