The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 02-05-2008
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
Code:
# FILE=mybigfile.txt

# ls -l $FILE
-rw-r--r--  1 root    staff     14639794 Aug 22 2006  mybigfile.txt

# awk 'BEGIN{"ls -l " "'$FILE'"|getline;printf "%s %5.2fMiB\n",$NF,$5/2^20}'
mybigfile.txt 13.96MiB

# awk 'BEGIN{"ls -l " "'$FILE'"|getline;printf "%s %5.2fMB\n",$NF,$5/10^6}'
mybigfile.txt 14.64MB
The above should work for any distro, provided that "ls" puts the filesize in column 5.

See Megabyte - Wikipedia for the differences between megabyte (MB) and mebibyte (MiB).