![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how can i print the output of the shell script in bigger size | mail2sant | Shell Programming and Scripting | 2 | 04-14-2008 05:07 AM |
| how to increase the size of the word in shell script | mail2sant | Shell Programming and Scripting | 3 | 04-07-2008 12:23 PM |
| shell script to find files by date and size | dadadc | UNIX for Dummies Questions & Answers | 1 | 10-20-2007 06:18 AM |
| Shell script to Find file size | ragsnovel | Shell Programming and Scripting | 1 | 08-10-2007 11:01 AM |
| Size of an array in sh shell script | trivektor | Shell Programming and Scripting | 1 | 09-29-2006 12:01 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Get file size in c shell script?
Hi,
I want to use an 'if statement' that will check if a certian file is greater in size than a certain value given by the user, but cannot get it to work. Do you have any ideas how this can be done? Your help is appreciated! |
|
|||||
|
how u feel this Quote:
To my understanding, you need to get the file size by something like: Code:
size=`ls -l $filename | awk '{print $5}'`
allowed_size=`expr ($size + 10240)/1024`
if ( $allowed_size > something) then
....
regards, rishi |
|
|||||
|
Quote:
Code:
size=`ls -l $filename | awk '{print $5}'`
Code:
size=`stat -c %s $filename` or much better Code:
size=$(stat -c %s $filename) vino |
|
|||||
|
Quote:
Code:
-size n[bckw]
File uses n units of space. The units are 512-byte blocks by
default or if b follows n, bytes if c follows n, kilobytes
if k follows n, or 2-byte words if w follows n. The size
does not count indirect blocks, but it does count blocks in
sparse files that are not actually allocated.
Code:
find /dir/to/search -size +10k will give you all files above 10kb. size will split up the data as follows Code:
text data bss dec hex filename 341349 10772 16 352137 55f89 file.ext We can see that 341349+10772+16 does give 352137. But doing an ls -l file.ext gives Code:
-rwxrwx--- 1 xxxxx xxxxx 505977 Sep 22 22:46 file.ext which gives a file size of 505977. Hence size will not give you the actual size of the file. Look at this article and this man page. It explains what size takes into consideration. vino Last edited by vino; 09-26-2005 at 05:45 AM.. |
|
||||
|
Filesize in if
Quote:
Hi, We can use following command to find out size of file and assign it to variable and then we can use it in if statment for compare ab=`ls -l $1 | awk '{print $5}'` Where $1 is file name for which to find out size. Regards Vinod |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|