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
How to determine if a file is done copying husker_ricky UNIX for Advanced & Expert Users 2 05-22-2008 08:32 AM
determine the physical size of the hard disk hoffies HP-UX 4 11-15-2007 01:08 AM
command to find out total size of a specific file size (spread over the server) abhinov SUN Solaris 3 08-08-2007 03:48 AM
How to determine the max file size dknight UNIX for Advanced & Expert Users 2 10-27-2006 05:39 AM
How to determine if a File is Open? derrikw2 UNIX for Advanced & Expert Users 2 02-01-2002 07:30 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-30-2003
alan's Avatar
Registered User
 

Join Date: Jul 2003
Location: Los Angeles
Posts: 53
Red face determine the size of a file???

Hello,

Can someone please tell me which command to use to determine the size of a file? When I log in to my shell account, I do this

$>% ls -als
total 632
8 -rw-r--r-- 1 user01 devgrp1 1558 Jul 30 23:25 .kshrc

What is "1158"? Bytes? Kilobytes?

I apologize if my question sounds stupid...I know I have a **lot** to learn?

Thanks in advance for teaching me!

Al.
Forum Sponsor
  #2 (permalink)  
Old 12-30-2003
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
alan,

Your file is listed in bytes. the smallest measurement of data commonly used.

If you remember or know anything of metric system:

Kilo ...=1000 bytes
mega =1000 kilo
giga ..=1000 mega
tera ..=1000 giga

If you want to experiment use the "prealloc" command. This will allow you to create files of any size allowed by your filesystem or OS.

prealloc <filename> <size>
__________________
My brain is your brain
  #3 (permalink)  
Old 12-30-2003
jsilva's Avatar
Registered User
 

Join Date: Apr 2003
Posts: 169
Hi,

Don't be afraid to ask... first always try the "man" command, it will teach you a lot... use it with "man command"...
Now, to answer to your question, and straight from the man page of ls command...

Quote:
ls -l (the long list) prints its output as follows for the
POSIX locale:

-rwxrwxrwx+ 1 smith dev 10876 May 16 9:42 part2

Reading from right to left, you see that the current direc-
tory holds one file, named part2. Next, the last time that
file's contents were modified was 9:42 A.M. on May 16. The
file contains 10,876 characters, or bytes. The owner of the
file, or the user, belongs to the group dev (perhaps indi-
cating ``development''), and his or her login name is smith.
The number, in this case 1, indicates the number of links to
file part2 (see cp(1)). The plus sign indicates that there
is an ACL associated with the file. Note: If the -@ option
has been specified, the presence of extended attributes will
supersede the presence of an ACL and the plus sign will be
replaced with an 'at' sign (@). Finally, the dash and
letters tell you that user, group, and others have permis-
sions to read, write, and execute part2.
  #4 (permalink)  
Old 12-30-2003
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
also note that the basic computer size is bits.

1 byte = 8 bits.
1kb = 1024 bytes
1mb = 1024 kb
1gb = 1024 mb
and so on.
  #5 (permalink)  
Old 12-30-2003
alan's Avatar
Registered User
 

Join Date: Jul 2003
Location: Los Angeles
Posts: 53
Re: determine the size of a file???

Quote:
Originally posted by alan
Hello,

Can someone please tell me which command to use to determine the size of a file? ...

Thanks to all of you for your replies. This helps me a great deal!! Thank you.
  #6 (permalink)  
Old 12-30-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,284
Things are not quite this simple. There are two different concepts of size here.

The 1558 does mean that a program can read 1558 bytes from this files. An attempt to read byte 1559 will fail with an EOF being returned. This is one concept of size.

But I think that Alan is actually interested in the second concept which is how much disk space is consumed by the file. The answer is that 8 * 512 = 4096 bytes of disk space is being using by this file. And that 8 came from the first column of the "ls" listing.

So if a program adds a byte to the file, making that 1558 to be a 1559, no additional disk space is needed.

This difference becomes very important because unix supports sparce files. If Alan wrote a program that seeks to byte 1,999,999,999 and writes a single byte, he will see something like this:
16 -rwx------ 1 root sys 2000000000 Dec 30 14:06 sparsefile

(Hmmmm... I would have predicted 8. Apparently a full block was allocated instead of a fragment. This was on HP-UX 11.00 on a vxfs filesystem.)

Database programs like Oracle will do this so it happens more often than you may think.

Here is my program in case you'd like to try it...
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

main()
{
        int fd;
        char byte=0;
        fd=open("sparsefile", O_CREAT|O_RDRW, 0700);
        lseek(fd, 1999999999, SEEK_SET);
        write(fd, &byte, 1);
        close(fd);
        exit(0);
}
  #7 (permalink)  
Old 12-30-2003
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
but when you brake it down to its essentials its still

1 byte = 8 bits.
1kb = 1024 bytes
1mb = 1024 kb
1gb = 1024 mb
and so on.

your 512 blocks and what not are parts of the way the fs is formated.

on aix and solaris when you do are defing the space for a fs you have to do it in 8byte chunks (i believe is the smalles piece you can chunk by.)

its all multiples of 8.

if your talking about how many blocks you are useing on the disk then you would have to look at the way the fs was formated.
Google UNIX.COM
Closed Thread

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:42 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