Skip to content

Instantly share code, notes, and snippets.

@hoodja
Created August 11, 2011 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoodja/1139459 to your computer and use it in GitHub Desktop.
Save hoodja/1139459 to your computer and use it in GitHub Desktop.
Quickly find project directories which have the fewest test files (really just fewest files)
for i in $(find . -name '*TestMain.cpp' -exec dirname {} \; | sort | uniq); do
echo "$(find $i -type f -depth 1 -maxdepth 1 | wc -l) $i";
done | sort -n | head
@magnusstahre
Copy link

How about this?

find . -name "*TestMain.cpp" | sed 's,/[^/]*$,,' | sort | uniq -c | sort -n | head

@hoodja
Copy link
Author

hoodja commented Aug 12, 2011 via email

@magnusstahre
Copy link

Good point. One thing to remember is that you are counting subdirectories as well as files now; if you just want to count files in a directory you can do something like

find $i -type f -depth 1 -maxdepth 1 | wc -l

@hoodja
Copy link
Author

hoodja commented Aug 12, 2011

I like that better - thanks Magnus!

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