I had to transfer a folder full of old projects to a new computer, and after trying to compress it, I realized the size was 8GB. A bit too much for some coding projects that only contain text files.
我不得不将一个充满旧项目的文件夹转移到新计算机上,并尝试对其进行压缩后,我意识到它的大小为8GB。 对于仅包含文本文件的某些编码项目来说,有点太多了。
They were all JavaScript projects, and every project contained a node_modules
folder.
它们都是JavaScript项目,每个项目都包含一个node_modules
文件夹。
The folder is totally unnecessary because I can always run npm install
in a project to re-generate it, and most of those projects I had in that folder were old things I’ll never use ever again.
该文件夹是完全不必要的,因为我总是可以在一个项目中运行npm install
来重新生成它,并且我在该文件夹中拥有的大多数项目都是旧的东西,我将不再使用。
So I decided to remove all the node_modules
folders, but they were too many. So I went into the parent folder, which I called dev
, and I ran this command in the ZSH terminal, the shell that comes by default with macOS Catalina:
因此,我决定删除所有的node_modules
文件夹,但是它们太多了。 因此,我进入了名为dev
的父文件夹,并在ZSH终端(macOS Catalina默认提供的shell)中运行了此命令:
find . -name "node_modules" -type d -prune -exec rm -rf '{}’ +
This reduced the size of my folder from 8GB to 2GB. Pretty nice for a one-line command.
这将我的文件夹大小从8GB减小到2GB。 单行命令非常好。
I found this command on this blog, there you can find more explanation on the command details.
我在此博客上找到了此命令,您可以在其中找到有关命令详细信息的更多说明。
翻译自: https://flaviocopes.com/how-to-bulk-remove-node-modules/