Skip to main content

TIL: 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

TIL: Disable mDNS and SSDP Discovery in Google Chrome

We're born alone, we live alone, we die alone. Only through our love and friendship can we create the illusion for the moment that we're not alone. — Orson Welles.

TIL: Flutter Series - Custom Icons

Everyone thinks of changing the world, but no one thinks of changing himself. — Leo Tolstoy.

TIL: Editor Series - Configuring Emacs To Fit The Needs Part 2

The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking. — Albert Einstein.

TIL: Gimp Automating Image Processing with Python Fu

What a large volume of adventures may be grasped within the span of his little life by him who interests his heart in everything. — Laurence Sterne.