Skip to content

Instantly share code, notes, and snippets.

@abdul
Last active July 11, 2017 19:33
Show Gist options
  • Select an option

  • Save abdul/ee3236e597a05acf534fb523c8ce2ca9 to your computer and use it in GitHub Desktop.

Select an option

Save abdul/ee3236e597a05acf534fb523c8ce2ca9 to your computer and use it in GitHub Desktop.
Remove .pyc files only when corresponding (source) .py doesn't exist.
#!/usr/bin/env bash
set -e
pycfiles=($(find . -name "*.pyc"))
for i in "${pycfiles[@]}"; do
pyfile="${i%.pyc}.py"
if [ ! -e "$pyfile" ]; then
echo "Removing "$i" because source file ("$pyfile") doesn't exist."
rm $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment