Cleaning up a code directory

I am configuring a new laptop, and I want to do it a little more cleanly than my last few migrations to a new machine. Rather than simply copying over all my files, I am being quite selective. As I work my way through some archives, I am learning to purge some unneeded files such as .pyc files from code directories.

# Remove all .pyc files from a directory, and all its subdirectories:
# Find only files ending in .pyc, then pipe them to the rm command.
find . -type f -name "*.pyc" | xargs rm -frv

# Remove all virtualenv directories from a directory tree:
find . -type d -name "venv" | xargs rm -frv

In doing this, one source directory went from ~8000 files to ~800 files, and from ~50MB to ~3MB. This also makes me rethink my backup script. I think my next backup script will exclude these files in the first place.


About ehmatthes

Teacher, hacker, new dad, outdoor guy
This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s