Skip to content

Instantly share code, notes, and snippets.

@eliascotto
Last active December 18, 2025 06:45
Show Gist options
  • Select an option

  • Save eliascotto/1e050638ba1e4a7a8352fd2a5cca07e6 to your computer and use it in GitHub Desktop.

Select an option

Save eliascotto/1e050638ba1e4a7a8352fd2a5cca07e6 to your computer and use it in GitHub Desktop.
Remove artifacts from the all the cargo target directories in a subdirectory
#!/bin/bash
# Check if a folder was passed as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <path-to-folder>"
exit 1
fi
# Absolute path of the base directory
BASE_DIR="$1"
# Find all directories containing Cargo.toml and run cargo clean in them
find "$BASE_DIR" -type f -name "Cargo.toml" | while read -r file; do
DIR="$(dirname "$file")"
echo "Running 'cargo clean' in: $DIR"
(cd "$DIR" && cargo clean)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment