If I issue the find command as follows:
$ find . -name *.ear
It prints out:
./dir1/dir2/earFile1.ear
./dir1/dir2/earFile2.ear
./dir1/dir3/earFile1.ear
What I want to 'print' to the command line is the name and the size:
./dir1/dir2/earFile1.ear 5000 KB
./dir1/dir2/earFile2.ear 5400 KB
./dir1/dir3/earFile1.ear 5400 KB
This should get you what you're looking for, formatting included (i.e. file name first and size afterward):
sample output (where I used
-iname "*.php"
to get some result):You need to use -exec or -printf. Printf works like this:
-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.
[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.
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:
Otherwise, use -exec ls -lh and pick out the size field from the output. Again on Solaris 10:
Try the following commands:
GNU
stat
:BSD
stat
:however
stat
isn't standard, sodu
orwc
could be a better approach:a simple solution is to use the -ls option in find:
That gives you each entry in the normal "ls -l" format. Or, to get the specific output you seem to be looking for, this:
Which will give you the filename followed by the size in KB.