【问题标题】:Is there a way to delete all node_module without opening the every single project from local drive?有没有办法在不从本地驱动器打开每个项目的情况下删除所有 node_module?
【发布时间】:2019-01-08 15:41:33
【问题描述】:

我有多个使用 node_modules 的项目,我在一个月内没有接触过。 如果我可以删除node_module,那只能节省我 5 到 8 GB 的存储空间。

我找到了Command line tool to delete folder with a specified name recursively in Windows 但这显示了删除特定文件夹中的文件,例如

D:\Project\Doing\prject1\
D:\Project\Complete\Project1\

FOR /d /r . %d IN (project1) DO @IF EXIST "%d" rd /s /q "%d"

但我不想搜索每个目录来查找 node_module 而是我想从我的 PC 中删除所有 node_module 文件夹(所有 驱动器)我该怎么做?

如果我需要返回 node_modules,我可以简单地运行 npm install,这样清理空间对我来说是个好主意。

【问题讨论】:

    标签: node.js windows npm command node-modules


    【解决方案1】:

    我发现here 的解决方案非常有效。

    find . -name "node_modules" -exec rm -rf '{}' +

    【讨论】:

      【解决方案2】:

      要列出所有 node_modules,请在命令舞会中使用此命令:

      FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"
      

      而删除你可以这样做:

      FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"
      

      这在 powershell 仅 cmd 中不起作用

      【讨论】:

      • 我相信你的命令会在D 目录中狂删除node_module,但想从所有目录( D C E) 中删除node_module
      • 我可以使用此命令在我的 PC 上找到所有 node_modules,但看起来您找到了适合您的解决方案 :)
      猜你喜欢
      • 1970-01-01
      • 2013-05-28
      • 2012-01-10
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      相关资源
      最近更新 更多