【问题标题】:I have many single files nested within many folders. Is there a way in Mac OSX to extract all the files into one folder?我有许多单个文件嵌套在许多文件夹中。 Mac OSX 中有没有办法将所有文件提取到一个文件夹中?
【发布时间】:2017-10-18 01:21:18
【问题描述】:

我最近有一个硬盘驱动器意外重新格式化,不得不求助于第三方软件来恢复文件。文件已恢复,但它们嵌套在多个文件夹中,例如:

Media/Mediatype/wmv Files/11-08-2014/recovered files/image.jpg. 

每个文件都包含在类似的内容中。我想知道是否有一个简单的 Mac OSX 终端选项,它基本上深入到每个文件夹路径并根据文件类型将其全部提取到一个文件夹中?谢谢!

【问题讨论】:

    标签: bash macos terminal finder


    【解决方案1】:

    这个怎么样?

    find . -type f -name "*.jpg" -print0 | xargs -0 -I {} mv {} ./jpg/
    

    您可以将"*.jpg" 更改为其他文件类型,并为它们创建一个文件夹并移动这些文件。示例:

    find . -type f -name "*.doc" -print0 | xargs -0 -I {} mv {} ./Documents/
    

    或者,如果您根本不想创建特定文件夹而只想将所有这些文件放在一个文件夹中,那么:

    find . -type f -print0 | xargs -0 -I {} mv {} ./allfiles/
    

    最后,您可以使用以下命令删除其他空目录。

    ls -1 | grep -v allfiles | xargs rm -rf
    

    【讨论】:

    • 在使用“mv”时要非常小心,以防多个文件夹中有名为“image.jpg”的文件……有些东西会丢失。也许改用“cp”。
    猜你喜欢
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    相关资源
    最近更新 更多