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

标签 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 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

关于file - 将多个目录中相同类型的所有文件上移一个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3686860/

相关文章:

php - 如何设置 PHP 命令行的最大调试/日志级别输出?

c++ - C++读取整个文件目录

java - Camel 删除文件异常

linux - 如何理解unix中的 `if [ ! -f $R_C_S_L/j_r_d* ] ...`?

c - gcc:与源文件位于同一文件夹中的链接库

linux - 如何使用 cut 命令忽略 CSV 文件中的逗号

linux - 从具有多字符分隔符的文本文件中提取列,即 "%$%"

linux - 如何在 bash 上按文件类型将文件分类到文件夹中(使用 'file' 命令)?

linux - 有没有办法让 shell 在脚本中间变得交互?

c++ - 支持管道(一个有用的 Hello World)