Check Total File Size of Files with Specific File Extension

It is simply this: do not tire, never lose interest, never grow indifferent—lose your invaluable curiosity and you let yourself die. It's as simple as that.
— Tove Jansson in Fair Play.

Hi guys, I’ve recently wondered on how to check the file size of all files with a specific file extension on a folder / project. This is what I’ve found out after several experimentation using command line tools in Linux, this specific task could be accomplish with just one line of command. Check below for the actual command:

find . -name "*.dart" | xargs cat | wc -c

What this command does, is first find all file with the dart extension. Then pipe the output of that command in xargs converts the standard input to command arguments. After that pipe the output of xargs again to our favorite word counter wc.

Here are the command line tools use in the process.

  • xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command. Some commands such as grep and awk can take input either as command-line arguments or from the standard input. Wikipedia
  • find is a command-line utility that locates files based on some user-specified criteria and then applies some requested action on each matched object. Wikipedia
  • wc is a command in Unix and Unix-like operating systems. The program reads either standard input or a list of files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow. Wikipedia

That’s it!

So guys, do you have any one-liner commands that you want to share? Just message me on my social media accounts. Hope you guys enjoyed this article!

Comments

Popular posts from this blog

Top Three DNS Providers That Provides Good Service in SEA (Southeast Asia)

Sending Email Using MailKit in ASP.NET Core Web API

Dirty Logging With Serilog For ASP.NET 5