Created
June 4, 2019 16:33
-
-
Save mehunk/4caa299beaf05905cfe541ea8fd44b22 to your computer and use it in GitHub Desktop.
遍历当前目录和子目录删除所有本地下载的 node_modules 依赖目录以节省磁盘空间。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# 迭代遍历所有的文件夹,清理下载的 node_modules 文件夹 | |
function read_dir(){ | |
if [ -d $1"/node_modules" ] | |
then | |
rm -rf $1"/node_modules" | |
echo "删除依赖成功!" | |
fi | |
for file in `ls $1` # 注意此处这是两个反引号,表示运行系统命令 | |
do | |
if [ -d $1"/"$file ] # 如果当前文件是目录。注意此处之间一定要加上空格,否则会报错 | |
then | |
read_dir $1"/"$file # 再进入子目录迭代查找 | |
fi | |
done | |
} | |
#读取第一个参数 | |
read_dir $1 |
find ./ -name node_modules |xargs rm -rf
Thank you! It really works and helps me!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
find ./ -name node_modules |xargs rm -rf