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

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"

Facebooktwitterredditpinterestlinkedinmail
Author: Dean WilliamsI'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips

Post Tags:
,
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments