【问题标题】:Move all files of same type in multiple directories up one folder将多个目录中相同类型的所有文件上移一个文件夹
【发布时间】:2010-09-10 17:36:31
【问题描述】:

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

【问题讨论】:

    标签: file unix command-line


    【解决方案1】:
    $ 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 . -name *.pdf(这不会复制或移动任何东西)。如果这与您感兴趣的文件匹配,请执行以下操作:find . -name *.pdf | xargs -I {} echo {}。输出应该是一样的。尽管如此,这不会移动或复制任何东西。然后cpmv
    猜你喜欢
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 2011-11-29
    • 1970-01-01
    相关资源
    最近更新 更多