我有多个npm项目保存在本地目录中。现在我想备份我的项目,但不包括node_modules文件夹,因为它占用了大量空间,并且可以使用npm install
随时恢复。
那么,如何使用命令行界面从指定路径递归删除所有node_modules文件夹呢?
我有多个npm项目保存在本地目录中。现在我想备份我的项目,但不包括node_modules文件夹,因为它占用了大量空间,并且可以使用npm install
随时恢复。
那么,如何使用命令行界面从指定路径递归删除所有node_modules文件夹呢?
虽然来晚了,但这是否会在 Linux 和 MacOS 上递归删除所有 node_modules?
rm -rf node_modules */node_modules */*/node_modules
Python脚本用于从多个项目中删除node_modules文件夹。只需将其放置在包含多个项目的项目文件夹中并运行即可。
import os
import shutil
dirname = '/root/Desktop/proj' #Your Full Path of Projects Folder
dirfiles = os.listdir(dirname)
fullpaths = map(lambda name: os.path.join(dirname, name), dirfiles)
dirs = []
for file in fullpaths:
if os.path.isdir(file): dirs.append(file)
for i in dirs:
dirfiles1 = os.listdir(i)
fullpaths1 = map(lambda name: os.path.join(i, name), dirfiles1)
dirs1 = []
for file in fullpaths1:
if os.path.isdir(file):
dirs1.append(file)
if(file[-12:]=='node_modules'):
shutil.rmtree(file)
print(file)
#!/bin/bash
# Script to clean all:
# - */node_modules
# - */dist
scriptDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cd "$scriptDir"
echo "Removing node_modules..."
args=(
. \( -name 'dist' -o -name 'node_modules' \) # find all folders with name dist or node_modules
-prune # exclude recursive search in subdirectories
-print # output results
-exec rm -rf '{}' + # delete all folders
)
find "${args[@]}"
echo "Done."
rm -rf node_modules */node_modules **/node_modules
- zaplec