Home > Net >  print the commands to delete node_modules folders recursively in a bash text file
print the commands to delete node_modules folders recursively in a bash text file

Time:07-15

I want this - https://stackoverflow.com/a/43561012/126833

find . -name 'node_modules' -type d -prune -exec rm -rf '{}'

except - instead of getting this done automatically, I want the all of the rm -rf /path/to/project/node_modules commands in a bash file like rm_node_modules.sh for me to review and then only I'll execute as bash rm_node_modules.sh

So basically my rm_node_modules.sh should be like :

rm -rf /path/to/project-1/node_modules
rm -rf /path/to/project-2/node_modules
rm -rf /path/to/project-3/node_modules

CodePudding user response:

You are on macOS where find does not support the -printf flag which would make this a bit simpler. But something like this will do the job:

find . -name node_modules -type d -print0 | xargs -0 stat -f "rm -rf %N" > rm_node_modules.sh
  • Related