Command to get file size.. | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Command to get file size..

UNIX for Dummies Questions & Answers


Tags
perl, perl shift, shift, shift perl

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-30-2007
preethgideon preethgideon is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 17 May 2012, 11:39 PM EDT
Posts: 79
Thanks: 3
Thanked 0 Times in 0 Posts
Command to get file size..

Hi,
Apart from ll -s, is there any way to check the file size.

I am working on a script to send a alert when the file size nears the ulimit.
So need the command that will show just the size in bytes.

Also clear my another doubt.When ulimit -a shows the following

time(seconds) unlimited
file(blocks) unlimited
data(kbytes) 1048576
stack(kbytes) 131072
memory(kbytes) unlimited
coredump(blocks) 4194303
nofiles(descriptors) 2048

Does it mean that any file created on this server will have no limit on the size ?

Thanks in advance.

Regards,
Gideon.
Sponsored Links
    #2  
Old 11-30-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
 
Join Date: Nov 2006
Last Activity: 20 November 2013, 8:29 AM EST
Location: Bulgaria
Posts: 1,419
Thanks: 0
Thanked 6 Times in 6 Posts
file means "The maximum size of files written by the shell and its children", so the answer is yes. For alternative on getting the file size you can use "stat", sample output :
Quote:
[sysgate@sysgate ~]$ stat data/unixbased.gif
File: `data/unixbased.gif'
Size: 7385 Blocks: 16 IO Block: 4096 regular file
Device: 803h/2051d Inode: 261934 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/sysgate) Gid: ( 500/sysgate)
Access: 2007-10-16 13:06:09.000000000 +0300
Modify: 2007-02-26 12:43:35.000000000 +0200
Change: 2007-10-16 13:06:05.000000000 +0300
Sponsored Links
    #3  
Old 11-30-2007
preethgideon preethgideon is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 17 May 2012, 11:39 PM EDT
Posts: 79
Thanks: 3
Thanked 0 Times in 0 Posts
Thank you for teaching me a new command.

But ls -s <file name> also gives in blocks itself right ? [ correct me if I am wrong ]

xx51007@edcuxdv3 /home/xx51007 > ls -s clscrn.pc
62 clscrn.pc

Also stat does not work in my system [ HP-UX]

Regards,
Gideon.
    #4  
Old 12-03-2007
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
 
Join Date: Feb 2004
Last Activity: 30 November 2011, 9:36 AM EST
Location: Oslo, Norway
Posts: 220
Thanks: 0
Thanked 1 Time in 1 Post
How about:

du -k <filename>

or

du -h <filename>

?
Sponsored Links
    #5  
Old 12-03-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 24 November 2014, 10:48 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 438 Times in 261 Posts
How about using perl to invoke the stat system call...

perl -e 'printf "%d\n" ,(stat(shift))[7]; ' somefile
should do it. And HP-UX has an older perl in /usr/contrib/bin in case you have not installed a modern version of perl.
Sponsored Links
    #6  
Old 12-03-2007
preethgideon preethgideon is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 17 May 2012, 11:39 PM EDT
Posts: 79
Thanks: 3
Thanked 0 Times in 0 Posts
Thanks both.
But Perderabo's solution works.I had a option earlier

ll clscrn.pc | awk '{ print $5 }' | tail -1

But wanted to know a single "commnad". Anyways thank everyone.

Regards,
Gideon.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
command to reduce size of file/directory??? nsharath Shell Programming and Scripting 2 01-21-2009 12:11 PM
command to read file name and size s_linux Shell Programming and Scripting 6 01-10-2009 02:50 PM
command to list file size rgordon HP-UX 3 12-05-2007 05:43 AM
Extracting only file size of the ls -ltr command. kingofprussia UNIX for Dummies Questions & Answers 6 12-03-2007 03:14 AM
command to find out total size of a specific file size (spread over the server) abhinov Solaris 3 08-08-2007 07:48 AM



All times are GMT -4. The time now is 09:35 PM.