-1

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!
___________________________________________________
Catlard
  • 853
  • 6
  • 13
  • 30
  • 1
    chepner's answer below explains what is wrong. But your command is weird: since you're using both `-print` and `rm`'s `-v` option, the number you'll get is (at least) twice the number of files actually removed! – gniourf_gniourf Jun 27 '16 at 15:48
  • @gniourf_gniourf Thanks! Got it. Will investigate! Man, I thought this function was cleaning up a lot more than it was! – Catlard Jun 27 '16 at 16:28
  • It may be OK for your case, but even if you drop the `-print`, the number of lines of output is *at least* as many as the number of files removed: if the output is `foo\nbar`, was that two files named `foo` and `bar`, or a single file with an embedded newline? – chepner Jun 27 '16 at 16:30

1 Answers1

3

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".

chepner
  • 497,756
  • 71
  • 530
  • 681
  • Ah yes. I believe my copying and pasting it to and from trello caused the wildcard characters to disappear. Overlooked that! Thanks. – Catlard Jun 27 '16 at 16:27