If I issue the find command as follows:
$ find . -name *.ear
It prints out:
./dir1/dir2/earFile1.ear
./dir1/dir2/earFile2.
If you need to get total size, here is a script proposal
#!/bin/bash
totalSize=0
allSizes=`find . -type f -name *.ear -exec stat -c "%s" {} \;`
for fileSize in $allSizes; do
totalSize=`echo "$(($totalSize+$fileSize))"`
done
echo "Total size is $totalSize bytes"
find . -name '*.ear' -exec du -h {} \;
This gives you the filesize only, instead of all the unnecessary stuff.
This should get you what you're looking for, formatting included (i.e. file name first and size afterward):
find . -type f -iname "*.ear" -exec du -ah {} \; | awk '{print $2"\t", $1}'
sample output (where I used -iname "*.php"
to get some result):
./plugins/bat/class.bat.inc.php 20K
./plugins/quotas/class.quotas.inc.php 8.0K
./plugins/dmraid/class.dmraid.inc.php 8.0K
./plugins/updatenotifier/class.updatenotifier.inc.php 4.0K
./index.php 4.0K
./config.php 12K
./includes/mb/class.hwsensors.inc.php 8.0K
Try the following commands:
GNU stat
:
find . -type f -name *.ear -exec stat -c "%n %s" {} ';'
BSD stat
:
find . -type f -name *.ear -exec stat -f "%N %z" {} ';'
however stat
isn't standard, so du
or wc
could be a better approach:
find . -type f -name *.ear -exec sh -c 'echo "{} $(wc -c < {})"' ';'
You could try this:
find. -name *.ear -exec du {} \;
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
5000 ./dir1/dir2/earFile1.ear
5400 ./dir1/dir2/earFile2.ear
5400 ./dir1/dir3/earFile1.ear
$ find . -name "test*" -exec du -sh {} \; 4.0K ./test1 0 ./test2 0 ./test3 0 ./test4 $
Scripter World reference