DEV Community

Xun Zhou
Xun Zhou

Posted on • Updated on

Tip for evaluating file size with linux command

I wanna just know the code size of current folder and wanna share this cod snippet with u. Give a try in your src folder . You will see there are some candidates, which might be too large and need to be refactored in the future.

For example: Service/Import.php with 1185 lines, and it does definitively too much and should be refactored.

cd src
find . -name '*.php' | xargs wc -l | sort -nr

20844 total
    1791 ./Service/PageGenerator.php
    1185 ./Modules/Importer/Service/Import.php
     542 ./Entity/Base/Area.php
     447 ./Entity/PublicInfo.php
     363 ./Controller/FrontendController.php
     339 ./Modules/MyAPI/Provider/Dto/AreasDto.php
     307 ./Entity/Base/OpeningTime.php
     298 ./Entity/Opening.php
     290 ./Entity/SpecialSale.php
     289 ./Modules/Exporter/Model/ExportStoresModel.php
     258 ./Entity/User.php
     232 ./Modules/MyAPI/Provider/Dto/PublicInfoDto.php
     230 ./Repository/StoreRepositoryDBAL.php
     221 ./Repository/StoreRepository.php
     214 ./Entity/Base/TemporaryClosing.php
     205 ./Controller/OpeningController.php
     196 ./Entity/Base/Competitor.php
     178 ./Form/PublicInfoType.php
     177 ./Modules/Exporter/Api/Bing/Stores.php
     177 ./Form/OpeningType.php
     173 ./Form/SpecialSaleType.php
     166 ./Entity/Base/StatusDevelopment.php
Enter fullscreen mode Exit fullscreen mode

[UPDATED] for the users, who is using zsh, can just use this shortcut:

$ cd src
$ wc -l **/*.php | sort -nr
Enter fullscreen mode Exit fullscreen mode

Sure, there are lots of code static tools that can do the same job. But this command is just handy 💫

Top comments (2)

Collapse
 
moopet profile image
Ben Sinclair

If you're running a shell that supports it out the box (like zsh) or something you can enable it on (like bash, if you have set shopt -s globstar) you can do the same with:

wc -l **/*.php
Enter fullscreen mode Exit fullscreen mode
Collapse
 
vikbert profile image
Xun Zhou

yes, it works well with your suggestion in zsh shell

$ wc -l **/*.php | sort -nr
Enter fullscreen mode Exit fullscreen mode