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

Check file size

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-15-2005
alnita alnita is offline
Registered User
 
Join Date: Jun 2005
Last Activity: 10 April 2007, 1:31 PM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Check file size

I need a unix script that will check the size of multiple files in the same directory or from a text file.
Sponsored Links
    #2  
Old 06-16-2005
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts
that will check the size of multiple files

What do you mean by check ?

Here is a script that will tell you the file size in bytes.


Code:
#! /bin/sh

ls > listing.txt

while read file
do
echo "Size of $file`stat -c=%s $file`"
done < listing.txt

Vino

Last edited by vino; 06-16-2005 at 01:36 AM..
Sponsored Links
    #3  
Old 06-16-2005
poste_d_ordure poste_d_ordure is offline
Registered User
 
Join Date: Jun 2005
Last Activity: 2 June 2006, 7:19 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I just need the size of one file

I tried manipulating the code and got an error that -c was not a valid option. When I tried the valid options, I got a rather complete list of stats, not just a numeric value for file size
    #4  
Old 06-16-2005
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts
How about


Code:
stat --format=%s $file

instead


Code:
stat -c=%s $file

From the man pages of stat,
Code:
-c

and
Code:
--format

are the same.

Dont know what effect it could have. Check it out.

Vino
Sponsored Links
    #5  
Old 06-16-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
 
Join Date: Mar 2005
Last Activity: 20 September 2013, 10:59 AM EDT
Location: Philadelphia metro
Posts: 958
Thanks: 3
Thanked 66 Times in 59 Posts
Quote:
Originally Posted by alnita
I need a unix script that will check the size of multiple files in the same directory or from a text file.
try ...

Code:
ls -l *

or ...

Code:
while read afile
do
    ls -l $afile
done < listfile

Sponsored Links
    #6  
Old 06-16-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
 
Join Date: Sep 2004
Last Activity: 26 July 2012, 3:38 PM EDT
Location: USA
Posts: 512
Thanks: 0
Thanked 2 Times in 2 Posts
ls -l | awk -F" " '{ print $5,$9 }'
Sponsored Links
    #7  
Old 06-20-2005
qfwfq qfwfq is offline
Registered User
 
Join Date: Feb 2005
Last Activity: 12 February 2010, 2:54 PM EST
Location: Canada
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Here is a script I have done to compile everyday statistics about files on the system. Let's say here, all files bigger than 500Mg.


Code:
REP=/home/user
LOG=filecheck.log
DATE=`date`

date >> $REP/$LOG

find . -size +1000000 -exec ls -l {} \; >>$REP/$LOG

Add it to your crontab and you can have a look everyday to the log file or send the output by mail to yourself.
Hope it helps!
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
check the file size sandy1028 Shell Programming and Scripting 1 11-11-2010 06:16 AM
Check the file size - help sithara Shell Programming and Scripting 5 06-10-2010 10:52 AM
Check for file size is zero or not. Hangman2 Shell Programming and Scripting 3 04-14-2009 04:08 PM
How to check the file size in a dir bsathishmca Shell Programming and Scripting 6 10-02-2008 10:26 AM
To check file size Shahul Shell Programming and Scripting 2 09-15-2008 11:53 AM



All times are GMT -4. The time now is 10:16 PM.