The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 10:29 AM
Very simple question roger19 UNIX for Dummies Questions & Answers 4 07-17-2006 04:36 PM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 09:03 AM
a simple question pnxi UNIX for Advanced & Expert Users 2 11-11-2003 10:10 PM
a very simple question (but i don't know) dell9 High Level Programming 1 10-29-2001 11:37 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-05-2008
Registered User
 

Join Date: Jul 2007
Posts: 72
Simple fle size question

I'm sure this is a simple one, but I'm new to UNIX and I can't figure it out.

How do I view file size in Megabytes? I have files in a directory and the size is 184710. I think this is in bytes but I'm not usre. How can I view this in MB.

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-05-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,128
for single file : "ls -lh file-name" , for directory - "du -sch /folder-name" # that's the total folder size.
That's on most GNU distros, what is your OS ?
Reply With Quote
  #3 (permalink)  
Old 02-05-2008
vbe vbe is offline
Registered User
 

Join Date: Sep 2005
Location: Switzerland
Posts: 430
man du (the arguments depend of OS... but what works on all is du -sk <filename> and result is in KB...)
Reply With Quote
  #4 (permalink)  
Old 02-05-2008
Registered User
 

Join Date: Oct 2007
Posts: 153
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).
Reply With Quote
  #5 (permalink)  
Old 02-05-2008
Registered User
 

Join Date: Feb 2008
Posts: 3
Quote:
Originally Posted by bbbngowc View Post
I'm sure this is a simple one, but I'm new to UNIX and I can't figure it out.

How do I view file size in Megabytes? I have files in a directory and the size is 184710. I think this is in bytes but I'm not usre. How can I view this in MB.

Thanks.
Depending on the OS you can use the -h option.
For example: ls -lh or du -sh *
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0