Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On Unix (Tru64), how to show file size in megabytes? This procudes sizes in bytes

ls -la
share|improve this question

migrated from stackoverflow.com Sep 20 '10 at 11:29

This question came from our site for professional and enthusiast programmers.

add comment

6 Answers

Maybe -h is sufficient for you:

-h
When used with the -l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to three or less using base 2 for sizes.

ls -lah

General advice: Use man commandname to read the manual of a certain commend, e.g. here man ls.

share|improve this answer
1  
Thanks, but -h option does not seem to exist on Tru64 Unix. –  atricapilla Sep 20 '10 at 11:26
4  
General advice: install GNU utilities ... –  reinierpost Sep 20 '10 at 12:35
    
+1 for the man pages(+5 if I could!). They are a priceless resource when you don't know how to do something with a particular command. –  Kevin M Sep 20 '10 at 13:54
5  
I like your tip about using man, but really, searching on Google is so much faster than using man a lot of the time (as now, when I found this result on Google). –  trusktr Mar 20 '13 at 5:00
    
Google's fine and all for general hints, but ultimately man pages are system/OS, even host specific, usually created when the software is compiled or installed, and thus, authoritative for the software on your particular system. –  Nevin Williams May 5 '13 at 4:33
show 1 more comment

ls --block-size=M prints the sizes in Megabytes but shows 1MB also for anything below 1 MB. I'm unsure if this option is acceptable in your UNIX version of ls, though.

Actually ls -lh also prints sizes in Gigabytes if the file is big enough (Well anyways: on Linux 64bit this does work :>)

On a side node: du -sh * prints also directory sizes in current directory.

share|improve this answer
add comment

You will have to use awk to do the math for you:

ls -l | awk 'BEGIN{mega=1048576} $5 >= mega {$5 = $5/mega "MB"} {print}'

This won't affect the output for files that are smaller than mega.

You may need to adjust the field number to match the way your ls is laid out. You can change mega to "1000000" if that is your preference.

This will print more decimal places than you probably want. You could implement a rounding function.

share|improve this answer
add comment

try ls -shR for recursive human readable format.

share|improve this answer
    
OP has stated that there is no -h on Tru64, and did so over two years before this answer was posted. –  Michael Kjörling Oct 11 '13 at 9:02
add comment

try ls -lash, it prints sizes in human readable format

share|improve this answer
add comment

du -sm filename.txt

share|improve this answer
    
it always round up the size...if size is less than 1 MB say 500K, then also it will print 1M –  Saumitra Jun 29 '12 at 13:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.