Dean Williams

Linux: Find all files matching name and print out file size and file path

You are currently viewing the Mobile Optimized version (AMP), some features may be missing or may not work as expected. Open Full Version.

Recently I needed to search the server and find all error_log files, but I needed to also list the size of each file that was found - the purpose of this was to find users with unnatually large error logs so that I oculd tweak the error_reporting settings on each system. I managed to find a very fast, very useful solution. The below searches all directories in /home/ for error_log and displays a list of all found files with the filesize first (in KB) followed by the files path.

find /home/ -name 'error_log' -printf "%p %k KB\n"
  But of course you can also search with wildcards, with the find command I can also find all .log files for instance.
find /home/ -name '*.log' -printf "%p %k KB\n"
Author: Dean WilliamsI'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips