Skip to content

Instantly share code, notes, and snippets.

@joelverhagen
Created October 8, 2012 16:48
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save joelverhagen/3853540 to your computer and use it in GitHub Desktop.
Save joelverhagen/3853540 to your computer and use it in GitHub Desktop.
Recursively removes all .pyc files and __pycache__ directories in the current directory
#!/bin/sh
# recursively removes all .pyc files and __pycache__ directories in the current
# directory
find . | \
grep -E "(__pycache__|\.pyc$)" | \
xargs rm -rf
# or, for copy-pasting:
# find . | grep -E "(__pycache__|\.pyc$)" | xargs rm -rf
@mehdisadeghi
Copy link

Or in your .zshrc:

alias rmpy='find . | grep -E "(__pycache__|\.pyc$)" | xargs rm -rf'

@amirshnll
Copy link

@joelverhagen thanks

@bezborodow
Copy link

There is no need to invoke grep, xargs, or rm. Try instead:

find . -regex '^.*\(__pycache__\|\.py[co]\)$' -delete

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