Created
February 7, 2023 05:48
-
-
Save turbotobias/61c8a74d3a8c42369fe4394ee8590df5 to your computer and use it in GitHub Desktop.
Delete all node_modules from sub-folders in a directory
This file contains hidden or 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 | |
| # Here is a shell script that deletes the node_modules folder from each folder found in the current working directory: | |
| # Deletes one level down, no recursion | |
| # Run this to allow deletion: | |
| # $ chmod +x./delete_node_modules.sh | |
| # Run this to delete: | |
| # $ ./delete_node_modules.sh | |
| for d in */; do | |
| # Check if the directory contains a node_modules folder | |
| if [ -d "$d/node_modules" ]; then | |
| # Delete the node_modules folder | |
| rm -rf "$d/node_modules" | |
| # Print a message indicating that the folder was deleted | |
| echo "Deleted node_modules in $d" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have some folders you do not want to delete
node_modulesfrom, you can use this: