All,
I have a script in which I use find command to filter out all png files in a given folder and list them along with their size. I want the output in the following format:
someFile.png => 1.2K
I'm using awk to to fetch $5(file size in human friendly format) and $9(path). Here is what I'm currently using:
find "$somePath" -iname "*.png" -print0 | xargs -0 ls -lh | awk '{print $9,"=>",$5}'
Sometimes the file names or the paths have spaces and this trips the script.
Here is an example output:
/Users/test/Desktop/Test/image1 => 1.2K
/Users/test/Desktop/Test/image1.png => 1.4K
The first entry in output is a file called "image1 test.png". I read somewhere that one should not parse the ls output. What's is the best way to tackle this?

ls -land then trying to extract just the pathname that was fed tolsin the first place. – geekosaur Apr 25 '12 at 21:38findoptions like-execor-execdir(generally safer). It'd be helpful if you described exactly what you wanted to do for each file. – jw013 Apr 25 '12 at 21:42awkalready does that. If you don't plan on any further processing of the files, just usels -shinstead of-lh, and get rid of theawk. – jw013 Apr 25 '12 at 21:50ls -sh, you can also usedu --apparent-size -h(probable GNU coreutils specific extension). – jofel Apr 26 '12 at 8:46