<p>If I issue the <a href="https://en.wikipedia.org/wiki/Find_(Unix)" rel="noreferrer">find</a> command as follows:</p>
<pre><code>find . -name *.ear
</code></pre>
<p>It prints out:</p>
<pre><code>./dir1/dir2/earFile1.ear
./dir1/dir2/earFile2.ear
./dir1/dir3/earFile1.ear
</code></pre>
<p>I want to 'print' the name and the size to the command line:</p>
<pre><code>./dir1/dir2/earFile1.ear  5000 KB
./dir1/dir2/earFile2.ear  5400 KB
./dir1/dir3/earFile1.ear  5400 KB
</code></pre>

[{'answer_id': 64666, 'author': 'Jeremy Weathers', 'author_id': 8794, 'author_profile': 'https://Stackoverflow.com/users/8794', 'pm_score': 0, 'selected': False, 'text': '<pre><code>find . -name "*.ear" -exec ls -l {} \\;\n</code></pre>\n'}, {'answer_id': 64678, 'author': 'Yaba', 'author_id': 7524, 'author_profile': 'https://Stackoverflow.com/users/7524', 'pm_score': 1, 'selected': False, 'text': '<p>You could try this:</p>\n\n<pre><code>find. -name *.ear -exec du {} \\;\n</code></pre>\n\n<p>This will give you the size in bytes. But the du command also accepts the parameters -k for KB and -m for MB. It will give you an output like</p>\n\n<pre><code>5000  ./dir1/dir2/earFile1.ear\n5400  ./dir1/dir2/earFile2.ear\n5400  ./dir1/dir3/earFile1.ear\n</code></pre>\n'}, {'answer_id': 64683, 'author': 'killdash10', 'author_id': 7621, 'author_profile': 'https://Stackoverflow.com/users/7621', 'pm_score': 1, 'selected': False, 'text': '<pre><code>find . -name "*.ear" | xargs ls -sh\n</code></pre>\n'}, {'answer_id': 64684, 'author': 'Michael Cramer', 'author_id': 1496728, 'author_profile': 'https://Stackoverflow.com/users/1496728', 'pm_score': 5, 'selected': False, 'text': '<p>A simple solution is to use the <em>-ls</em> option in <em>find</em>:</p>\n<pre><code>find . -name \\*.ear -ls\n</code></pre>\n<p>That gives you each entry in the normal &quot;ls -l&quot; format. Or, to get the specific output you seem to be looking for, this:</p>\n<pre><code>find . -name \\*.ear -printf &quot;%p\\t%k KB\\n&quot;\n</code></pre>\n<p>Which will give you the filename followed by the size in KB.</p>\n'}, {'answer_id': 64691, 'author': 'Leigh Caldwell', 'author_id': 3267, 'author_profile': 'https://Stackoverflow.com/users/3267', 'pm_score': 7, 'selected': False, 'text': '<p>You need to use -exec or -printf. Printf works like this:</p>\n\n<pre><code>find . -name *.ear -printf "%p %k KB\\n"\n</code></pre>\n\n<p>-exec is more powerful and lets you execute arbitrary commands - so you could use a version of \'ls\' or \'wc\' to print out the filename along with other information. \'man find\' will show you the available arguments to printf, which can do a lot more than just filesize.</p>\n\n<p>[edit] -printf is not in the official POSIX standard, so check if it is supported on your version. However, most modern systems will use GNU find or a similarly extended version, so there is a good chance it will be implemented.</p>\n'}, {'answer_id': 64699, 'author': 'shyam', 'author_id': 7616, 'author_profile': 'https://Stackoverflow.com/users/7616', 'pm_score': 8, 'selected': True, 'text': "<pre><code>find . -name '*.ear' -exec ls -lh {} \\;\n</code></pre>\n\n<p>just the h extra from jer.drab.org's reply. saves time converting to MB mentally ;)</p>\n"}, {'answer_id': 64770, 'author': 'dmazzoni', 'author_id': 7193, 'author_profile': 'https://Stackoverflow.com/users/7193', 'pm_score': 5, 'selected': False, 'text': '<p>Using GNU find, I think this is what you want.  It finds all real files and not directories (<em>-type f</em>), and for each one prints the filename (%p), a tab (\\t), the size in kilobytes (%k), the suffix &quot; KB&quot;, and then a newline (\\n).</p>\n<pre><code>find . -type f -printf \'%p\\t%k KB\\n\'\n</code></pre>\n<p>If the <em>printf</em> command doesn\'t format things the way you want, you can use <em><a href="https://linux.die.net/man/1/exec" rel="nofollow noreferrer">exec</a></em>, followed by the command you want to execute on each file.  Use {} for the filename, and terminate the command with a semicolon (;).  On most shells, all three of those characters should be escaped with a backslash.</p>\n<p>Here\'s a simple solution that finds and prints them out using &quot;ls -lh&quot;, which will show you the size in human-readable form (<em>k</em> for kilobytes and <em>M</em> for megabytes):</p>\n<pre><code>find . -type f -exec ls -lh \\{\\} \\;\n</code></pre>\n<p>As yet another alternative, &quot;wc -c&quot; will print the number of characters (bytes) in the file:</p>\n<pre><code>find . -type f -exec wc -c \\{\\} \\;\n</code></pre>\n'}, {'answer_id': 244894, 'author': 'tpgould', 'author_id': 32161, 'author_profile': 'https://Stackoverflow.com/users/32161', 'pm_score': 2, 'selected': False, 'text': "<p>Awk can fix up the output to give just what the questioner asked for. On my Solaris 10 system, find -ls prints size in KB as the second field, so:</p>\n\n<pre><code>% find . -name '*.ear' -ls | awk '{print $2, $11}'\n5400 ./dir1/dir2/earFile2.ear\n5400 ./dir1/dir2/earFile3.ear\n5400 ./dir1/dir2/earFile1.ear\n</code></pre>\n\n<p>Otherwise, use -exec ls -lh and pick out the size field from the output.\nAgain on Solaris 10:</p>\n\n<pre><code>% find . -name '*.ear' -exec ls -lh {} \\; | awk '{print $5, $9}'\n5.3M ./dir1/dir2/earFile2.ear\n5.3M ./dir1/dir2/earFile3.ear\n5.3M ./dir1/dir2/earFile1.ear\n</code></pre>\n"}, {'answer_id': 2008917, 'author': 'scripter', 'author_id': 244232, 'author_profile': 'https://Stackoverflow.com/users/244232', 'pm_score': 1, 'selected': False, 'text': '<pre>\n$ find . -name "test*" -exec du -sh {} \\;\n4.0K    ./test1\n0       ./test2\n0       ./test3\n0       ./test4\n$\n</pre>\n\n<p><a href="http://www.scripterworld.com/2009/07/unix-find-command-with-examples-and.html" rel="nofollow noreferrer">Scripter World reference</a></p>\n'}, {'answer_id': 8364384, 'author': 'Mike M', 'author_id': 1078432, 'author_profile': 'https://Stackoverflow.com/users/1078432', 'pm_score': 2, 'selected': False, 'text': "<p>I struggled with this on Mac OS X where the find command doesn't support <code>-printf</code>.</p>\n\n<p>A solution that I found, that admittedly relies on the 'group' for all files being 'staff' was...</p>\n\n<pre><code>ls -l -R | sed 's/\\(.*\\)staff *\\([0-9]*\\)..............\\(.*\\)/\\2 \\3/'\n</code></pre>\n\n<p>This splits the ls long output into three tokens</p>\n\n<ol>\n<li>the stuff before the text 'staff'</li>\n<li>the file size</li>\n<li>the file name</li>\n</ol>\n\n<p>And then outputs tokens 2 and 3, i.e. output is number of bytes and then filename</p>\n\n<pre><code>8071 sections.php\n54681 services.php\n37961 style.css\n13260 thumb.php\n70951 workshops.php\n</code></pre>\n"}, {'answer_id': 14184795, 'author': 'Andreas', 'author_id': 1953201, 'author_profile': 'https://Stackoverflow.com/users/1953201', 'pm_score': 2, 'selected': False, 'text': '<p>Why not use <strong>du -a</strong> ? E.g. </p>\n\n<pre><code>find . -name "*.ear" -exec du -a {} \\;\n</code></pre>\n\n<p>Works on a Mac</p>\n'}, {'answer_id': 21101734, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': "<pre><code>find . -name '*.ear' -exec du -h {} \\;\n</code></pre>\n\n<p>This gives you the filesize only, instead of all the unnecessary stuff.</p>\n"}, {'answer_id': 22691385, 'author': 'adriano72', 'author_id': 988044, 'author_profile': 'https://Stackoverflow.com/users/988044', 'pm_score': 2, 'selected': False, 'text': '<p>This should get you what you\'re looking for, formatting included (i.e. file name first and size afterward):</p>\n\n<pre><code>find . -type f -iname "*.ear" -exec du -ah {} \\; | awk \'{print $2"\\t", $1}\'\n</code></pre>\n\n<p>sample output (where I used <code>-iname "*.php"</code> to get some result):</p>\n\n<pre><code>./plugins/bat/class.bat.inc.php  20K\n./plugins/quotas/class.quotas.inc.php    8.0K\n./plugins/dmraid/class.dmraid.inc.php    8.0K\n./plugins/updatenotifier/class.updatenotifier.inc.php    4.0K\n./index.php      4.0K\n./config.php     12K\n./includes/mb/class.hwsensors.inc.php    8.0K\n</code></pre>\n'}, {'answer_id': 35129844, 'author': 'kenorb', 'author_id': 55075, 'author_profile': 'https://Stackoverflow.com/users/55075', 'pm_score': 2, 'selected': False, 'text': '<p>Try the following commands:</p>\n\n<p>GNU <code>stat</code>:</p>\n\n<pre><code>find . -type f -name *.ear -exec stat -c "%n %s" {} \';\'\n</code></pre>\n\n<p>BSD <code>stat</code>:</p>\n\n<pre><code>find . -type f -name *.ear -exec stat -f "%N %z" {} \';\'\n</code></pre>\n\n<p>however <code>stat</code> isn\'t standard, so <code>du</code> or <code>wc</code> could be a better approach:</p>\n\n<pre><code>find . -type f -name *.ear -exec sh -c \'echo "{} $(wc -c &lt; {})"\' \';\'\n</code></pre>\n'}, {'answer_id': 62017923, 'author': 'Damien C', 'author_id': 2261243, 'author_profile': 'https://Stackoverflow.com/users/2261243', 'pm_score': 0, 'selected': False, 'text': '<p>If you need to get total size, here is a script proposal</p>\n\n<pre><code>#!/bin/bash\ntotalSize=0\n\nallSizes=`find . -type f -name *.ear -exec stat -c "%s" {} \\;`\n\nfor fileSize in $allSizes; do\n    totalSize=`echo "$(($totalSize+$fileSize))"`\ndone\necho "Total size is $totalSize bytes"\n</code></pre>\n'}, {'answer_id': 67577432, 'author': 'NILESH KUMAR', 'author_id': 5036094, 'author_profile': 'https://Stackoverflow.com/users/5036094', 'pm_score': -1, 'selected': False, 'text': '<p>You could try for loop:</p>\n<pre><code>for i in `find . -iname &quot;*.ear&quot;`; do ls -lh $i; done\n</code></pre>\n'}, {'answer_id': 69855684, 'author': 'Craig', 'author_id': 529256, 'author_profile': 'https://Stackoverflow.com/users/529256', 'pm_score': 2, 'selected': False, 'text': "<p>Just list the files (<code>-type f</code>) that match the pattern (<code>-name '*.ear</code>) using the disk-usage command (<code>du -h</code>) and sort the files by the human-readable file size (<code>sort -h</code>):</p>\n<pre><code>find . -type f -name '*.ear' -exec du -h {} \\; | sort -h\n</code></pre>\n<p>Output</p>\n<pre><code>5.0k  ./dir1/dir2/earFile1.ear\n5.4k  ./dir1/dir2/earFile2.ear\n5.4k  ./dir1/dir3/earFile1.ear\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/64649', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/700/']