Skip to content

Instantly share code, notes, and snippets.

@seanwalsh
Last active May 17, 2023 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanwalsh/ef90954ec7ff0586754a602cf7dd5f2e to your computer and use it in GitHub Desktop.
Save seanwalsh/ef90954ec7ff0586754a602cf7dd5f2e to your computer and use it in GitHub Desktop.
A shell script to delete a yarn.lock file and the node_modules directory.
#!/bin/zsh
# Check if node_modules directory exists
if [ -d "node_modules" ]; then
echo "Deleting node_modules directory..."
rm -rf node_modules
echo "node_modules directory deleted."
else
echo "node_modules directory does not exist."
fi
# Check if yarn.lock file exists
if [ -f "yarn.lock" ]; then
echo "Deleting yarn.lock file..."
rm yarn.lock
echo "yarn.lock file deleted."
else
echo "yarn.lock file does not exist."
fi

Here's how to use the script:

  1. Save the script to a file, for example cleanup.sh.
  2. Make the script executable by running chmod +x cleanup.sh in your terminal.
  3. Run the script using ./cleanup.sh in your terminal.

This script should be run from the directory containing the node_modules directory and yarn.lock file you want to delete. Be careful with this script as it will delete these items without asking for confirmation. If you want a confirmation prompt before deletion, you can modify the rm commands to rm -i to ask for confirmation before each deletion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment