Monday, March 7, 2011

Use wc -l For Quick Overviews Of New Rails Projects

Update: James Golick made this code better.

It's your first day with a new code base. You're going to need to know which are the biggest files, which are the smallest, and how the sizes are distributed.

for MODEL in `ls app/models/`; do echo $MODEL; wc -l app/models/$MODEL; done

for CONTROLLER in `ls app/controllers/`; do echo $CONTROLLER; wc -l app/controllers/$CONTROLLER; done

for VIEW_DIR in `ls app/views/`; do for VIEW in `ls app/views/$VIEW_DIR`; do echo $VIEW_DIR $VIEW; wc -l app/views/$VIEW_DIR/$VIEW ; done; done

wc stands for "word count"; wc -l gives you the number of lines in a file. (The "l" stands for "line.")