copy this code and execute in directory where you want to save your script
wget https://raw.githubusercontent.com/belarusrulez/clean_fcpx/main/clean_fcpx.sh
chmod +x clean_fcpx.sh
from script directory run
back up your project before you will use the script. report any issues.
./clean_fcpx.sh ${FULL_PATH_TO_YOUR_LIBRARY}