determine the size of a file???


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers determine the size of a file???
# 1  
Old 12-30-2003
Power 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.
# 2  
Old 12-30-2003
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>
# 3  
Old 12-30-2003
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  
Old 12-30-2003
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  
Old 12-30-2003
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  
Old 12-30-2003
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  
Old 12-30-2003
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I determine the best number to use for the bs (block size) operand of the dd command?

When I create a bootable Linux distro installation USB drive, I use this command: sudo dd if=/Path/to/linux_distro.iso of=/dev/rdisk<disk number> bs=<number of bytes> When I look it up, I've seen variations of people choosing 4M, and I think 8M, 2M, and maybe even 1M. If I leave the operand... (4 Replies)
Discussion started by: Quenz
4 Replies

2. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

3. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

4. Programming

Perl : Inline program to determine file size

Hi, I have 5 files as below $ ll sam* -rw-rw-rw- 1 sam ugroup 0 Mar 21 06:06 sam3 -rw-rw-rw- 1 sam ugroup 0 Apr 3 22:41 sam2 -rw-rw-rw- 1 sam ugroup 17335 Apr 10 06:07 sam1 -rw-rw-rw- 1 sam ugroup 5 Apr 10 07:53 sam5 -rw-rw-rw- 1 sam ugroup 661 Apr 10 08:16 sam4 I want to list out... (4 Replies)
Discussion started by: sam05121988
4 Replies

5. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

6. UNIX for Dummies Questions & Answers

Determine switch buffer size

Hi everybody, I need to calculate the tcp buffer size of a network switch, since it's not specified in the manual; how do I do this? I have some machines connected to the switch and I can run some socket tests written in C between these machines (I can choose how many bytes to send and... (0 Replies)
Discussion started by: dimpim
0 Replies

7. Shell Programming and Scripting

The scripts not able to make the file to size 0, every times it go back to its original size

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (0 Replies)
Discussion started by: mridul10_crj
0 Replies

8. HP-UX

determine the physical size of the hard disk

Hi is there a cmd in hpux 11 to determine the physical size of the hard disk. not bdf command. i have searched the other threads here but cant find an answer. thank you guys (4 Replies)
Discussion started by: hoffies
4 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. UNIX for Advanced & Expert Users

How to determine the max file size

Does anyone know a way to determine the maximum filesize on a file system on Solaris, HP-UX, AIX, Linux, and OSF1 using the command line? TIA (2 Replies)
Discussion started by: dknight
2 Replies
Login or Register to Ask a Question