【问题标题】:Automatically move folders based on file name?根据文件名自动移动文件夹?
【发布时间】:2013-11-20 19:03:14
【问题描述】:

我有大约 1500 个文件夹需要通过命令行自动组织。

我正在寻找一种方法来搜索包含 /lib/file.php 的所有文件夹 - 如果 file.php 确实存在于 lib 文件夹中,我需要将根文件夹(lib 上一层)移至新目录.

我知道如何搜索包含/lib/file.php 的所有文件夹,但不知道如何将它们自动移动到新文件夹中。例如,如果/test123/lib/file.php 存在,那么test123 文件夹应该移动到一个新文件夹中...

【问题讨论】:

    标签: shell command-line ssh command


    【解决方案1】:

    尝试使用findsedxargsmv管道

    find -type f -wholename '*/lib/file.php' | sed 's:/lib/file\.php$::' | xargs -I dirs mv dirs /path/to/new/dir/
    

    【讨论】:

      【解决方案2】:

      可能是这样的:

      for d in *
      do
        if [[ -r "${d}/lib/file.php" ]]
        then
          mv "${d}" "/some/new/place/."
        fi
      done
      

      【讨论】:

        猜你喜欢
        • 2017-06-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-29
        • 1970-01-01
        • 2015-10-09
        相关资源
        最近更新 更多