Simple fle size question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Simple fle size question
# 1  
Old 02-05-2008
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.
# 2  
Old 02-05-2008
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 ?
# 3  
Old 02-05-2008
man du (the arguments depend of OS... but what works on all is du -sk <filename> and result is in KB...)
# 4  
Old 02-05-2008
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).
# 5  
Old 02-05-2008
Quote:
Originally Posted by bbbngowc
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 *
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple question

Sorry for stupid question, but why this script gives that output? $ awk 'BEGIN { well=56789; print 1234$well }' 1234 I expected 123456789 (9 Replies)
Discussion started by: silyin
9 Replies

2. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

3. UNIX for Dummies Questions & Answers

simple(?) if/else question

Hello, I have a quick question that is not related to homework in any way shape or form (in case anyone wanted to know). My question is thus: I have a file "temp" that has the two values say "5" and "3" (separated by a white space). Now, I want to simply write an if-else statement that reads... (10 Replies)
Discussion started by: astropi
10 Replies

4. Shell Programming and Scripting

Simple Question

Hi, Please don't berate me over the simplicity of these questions. I have recently gotten into bash shell scripting and enjoy it quite a bit. One thing I have not found the answer to though is when naming a shell script, what extension is normally used (ie myscript.?)? Also where is the standard... (5 Replies)
Discussion started by: msb65
5 Replies

5. Shell Programming and Scripting

append to fle using sed

Hello , I have the folloiwing command : sed -n "$var,$final w $destfile" $sourcefile where : $var - $final represent the range of line numbers to be written in $destfile However I require this command to work in a loop for which i need the sed command to keep appending the output to the... (2 Replies)
Discussion started by: shweta_d
2 Replies

6. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

7. UNIX for Dummies Questions & Answers

simple if then fi question

i'm trying to make a script that prints the name of the script for any command line parameter, here is what i have, and get `]]' unexpected: what am i doing wrong? (3 Replies)
Discussion started by: tefflox
3 Replies

8. Shell Programming and Scripting

Simple question.

Is it possible to establish an IF statement inside a case statement in a shell file ? thx (2 Replies)
Discussion started by: TARFU
2 Replies

9. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

10. UNIX for Dummies Questions & Answers

Simple question

I am taking an intro to unix class and I can not figure out how to do part of the question. I am writing script to be exictued by a program in the tutoral. Question: Write every line containing the word ``delete'' produced by ``man mail'' into a file called ``delete''. Hint: What does using... (1 Reply)
Discussion started by: weathergirl
1 Replies
Login or Register to Ask a Question