Compare all files in a directory to a threshold value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare all files in a directory to a threshold value
# 1  
Old 04-29-2009
Compare all files in a directory to a threshold value

Hi guys,

I have the following, and would like to enhance it be be able to run it in the hard coded directory and compare each file in the directory with the
Code:
expectedSize

How would I go about doing this?
Thanks,
Bloke

Code:
#!/bin/sh
[[ -n "$1" ]] || { echo "Usage: watchSizes 400"; exit 0 ; }

#Hammer: How long should the DRP files be?
#seconds * 16000  = 4800000 bytes (approx 4.7MB)


seconds=$1;
bitsPerSecond=16000;
echo "Seconds : " $seconds;
expectedSize=$(($seconds*$bitsPerSecond));
echo "expected: " $expectedSize;

theDirectory=/usr2/fubar/dirgaf

# 2  
Old 04-29-2009
Are you on Linux - if so the stat command gives filesizes, otherwise you will have to loop through the output of ls -l, comparing the filesize in bytes in output with 4800000.

The find command also supports the -size option --
Code:
upper=$(( $expectedSize + 2000 ))
lower=$(( $expectedSize - 2000 ))
find $theDirectory \( -size +${lower}c -a -size -${upper}c \) -exec ls -l {} \;

returns files that are close to the size you gave, for example.



[/code]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare directories and copy differences (files) in a another directory

Hey im working on script that can compare 2 directory and check difference, then copy difference files in third diretory. here is the story: in folder one we have 12 subfolder and in each of them near 500 images hosted. 01 02 03 04 05 06 07 08 09 10 11 12 in folder 2 we have same subfolder... (2 Replies)
Discussion started by: nimafire
2 Replies

2. Shell Programming and Scripting

Compare Only "File Names" in 2 Files with file lists having different directory structure

I have a tar arcive arch_all.tar.gz and 4 batched tar archive . These batches are supposed to have all the files form arch1.all.tar.gz arch1_batch1.tar.gz arch1_batch2.tar.gz arch1_batch3.tar.gz arch1_batch4.tar.gz my issue is that the directory structure in "arch_all.tar.gz" is... (6 Replies)
Discussion started by: sumang24
6 Replies

3. Shell Programming and Scripting

perl Compare zone files in directory with what is listed in named.conf

I would really appreciate any assistance that I can get here. I am fairly new to perl. I am trying to rewrite my shell scripts to perl. Currently I have a shell script (using sed, awk, grep, etc) that gets a list of all of the zone files in a directory and then looks in named.conf for what... (0 Replies)
Discussion started by: brianjb
0 Replies

4. Shell Programming and Scripting

Parse files in directory and compare with another file

I have two files File 1 in reading directory is of following format Read 1 A T Read 3 T C Read 5 G T Read 7 A G Read 10 A G Read 12 C G File 2 in directory contains Read 5 A G Read 6 T C Read 7 G A Read 8 G A Read 20 A T File2 contains (1 Reply)
Discussion started by: empyrean
1 Replies

5. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

6. Shell Programming and Scripting

Script for deleting files and directories when the file system reaches the threshold

Hi Can someone assist in writing a script. I have a filesystem named /sybase in my aix lpar. When this filesystem becomes 94% full all the files and directories under /sybase/logs should be deleted immediately. :confused: (7 Replies)
Discussion started by: newtoaixos
7 Replies

7. Shell Programming and Scripting

Diff two files with threshold value

i have two big file which have thousand of line. i have to sort on two key fields then diff the file. if the interger value of one of the column is less then or greater then 1 it should ignore it. for example File1 abc|7000|jhon|2.3 xyz|9000|sam|6.7 pqr|8000|kapi|4.6 File2... (11 Replies)
Discussion started by: Nishi2011
11 Replies

8. Shell Programming and Scripting

Compare files in a directory

Hi friends, can anyone help me comparing files in a directory. I have files f1, f2, f3, f4, f5, f6, f7, f8 in a directory each created on a daily basis as f1 on day1, f2 on day2, f3 on day3, f4 on day4, f5 on day5, f6 on day6, f7 on day7, f8 on day8. I need ignore the latest two files (here f7 and... (5 Replies)
Discussion started by: nmattam
5 Replies

9. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

10. Shell Programming and Scripting

compare files in two directories and output changed files to third directory

I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together. I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Discussion started by: bkeep
4 Replies
Login or Register to Ask a Question