Tip for evaluating file size with linux command

vikbert

Xun Zhou

Posted on June 10, 2022

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 💫

💖 💪 🙅 🚩
vikbert
Xun Zhou

Posted on June 10, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024