How to Find Files and Print Their Exact Sizes in Ubuntu (find -printf)

The Missing Metadata

By default, the Linux find command only outputs the absolute path of the files it locates. If you are searching a server for large log files or attempting to calculate the total storage impact of a specific file type, seeing a list of 500 file paths is useless without knowing how large they actually are. While you can pipe the output into ls -l or du, the most efficient and native method is to instruct the find engine itself to format its own output and inject the exact file size directly into the terminal window.

Using the find Command with -printf

The Linux find command utilizes the -printf flag, which allows you to define a custom format string using variables. In this case, %s represents the exact file size in bytes, and %p represents the file path.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the /var/log/ directory for all text files and print their exact size in bytes next to their name, type the following command exactly:
  3. find /var/log/ -name "*.txt" -printf "%s bytes - %p\n"
  4. Press Enter.

Formatting the Output

The command structure here is highly customizable. The %s prints the byte size, the string bytes - is literal text that you defined to make the output readable, the %p prints the absolute path of the file, and the \n guarantees that each result is placed on a brand new line. This transforms the find command from a simple location tool into a powerful, real-time auditing script, allowing you to instantly assess the storage impact of the files you are locating without relying on external piping commands.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.