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?

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

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.

| improve this answer | |
  • 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 '16 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 – user4556274 Dec 27 '16 at 19:00
  • @ user4556274 Ah, thank you. I'll keep that in mind for next time. – Kevin M Dec 27 '16 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.