Search code examples
bashmacosterminaliterm2

Broken bash function


Since I've wiped my OSX install and rebooted, this bash function no longer works. I can clearly see that there are .orig and .pyc files in the folder I'm running it on, but it just tells me it can't find anything. I forget exactly how this function works. Can anyone help me understand what's wrong? Thanks!

studyClean() {
echo "------------Cleaning...------------"
numCleaned=$(find . -type f -name ".pyc" -print -exec rm -v {} + | wc -l;)
echo "${numCleaned} .pyc files cleaned!"
numCleaned=$(find . -type f -name ".orig" -print -exec rm -v {} + | wc -l;)
echo "${numCleaned} .orig files cleaned!"
}

Terminal output when called:

| ~/apps/funapp @ Simons-Air (simonbraunstein)
| => studyClean
------------Cleaning------------
       0 .pyc  files cleaned!
       0 .orig files cleaned!
___________________________________________________

Solution

  • It's not clear why the function worked in the first place. The arguments to -name should only match files with the exact names .pyc and .orig. Instead, use -name "*.pyc" and -name "*.orig".