0

I am using SSH to access my Ubuntu system and I have 100s of files across 100s of folders which are called xxxxx.mail.log or xxxx.mail.log.xxx I need to list all these files, and see their file size.

I have already tried ncdu, which works, but I can’t search for filenames with it. Doing it manually with ncdu takes hours.

What’s the easiest way to search my system for all files that contain mail.log in their filename, and have them listed and display the file size?

2
  • 3
    find / -name "*.mail.log*" -printf "%s\t%p\n" Dec 27, 2016 at 18:40
  • 1
    What does the -printf "%s\t%p\n" do?
    – Kevin M
    Dec 27, 2016 at 18:42

1 Answer 1

3

Try

find / -name "*mail.log*" -printf "%s\t%p\n"

-printf prints some information about each match, in this case:

%s - size of file in bytes
\t - tab for spacing
%p - pathname
\n - newline

See man find and search for "printf format" to list all possibilities for the printf statement.

3
  • Thank you! This worked. What I used in the end was find / -name "*.mail.log*" -printf "%s\t%p\n" >findresults.txt then downloaded the file and copied the content into google spreadsheet and ordered by the file size column.
    – Kevin M
    Dec 27, 2016 at 18:57
  • @KevinM, the sorting could easily be done in the same command pipeline (although redirecting to a file and manipulating that works also). find / -name "*mail.log*" -printf "%s\t%p\n" | sort -n Dec 27, 2016 at 19:00
  • @ user4556274 Ah, thank you. I'll keep that in mind for next time.
    – Kevin M
    Dec 27, 2016 at 19:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .