Trying to find files equal to and greater than


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to find files equal to and greater than
# 1  
Old 07-05-2010
Trying to find files equal to and greater than

Hi Guys and Gals,

I'm having some difficulty putting this check into a shell script. I would like to search a particular directory for a number of files. The logic I have is pretty simple:

Find file named *.txt that are newer than <this file> and count them
If the number of files is equal to or greater than 1 echo "all is good"
Otherwise echo "all is not good"

I'm having difficulty using -eq | -gt at the same time.

I have a variable

Code:
filecount=`ls -l | wc -l`
if [filecount -eq 1] 
echo all is good

How do I get it to do equal and greater than in the same line?
# 2  
Old 07-05-2010
Code:
if [ $filecount -ge 1 ]

# 3  
Old 07-05-2010
Easy as that huh?

Thanks. I just realized it would've also worked if I had just said greater than 0. Smilie


Thanks
# 4  
Old 07-05-2010
Only that that condition will always be true, as "ls -l" will print at least the "total" line. If you use only "ls", without any options, you'll get the correct file count (ls, if not printing to a TTY, will only list 1 file per line)
# 5  
Old 07-06-2010
In one of my directories there are about 1300 files and the script is giving me the arg list too long error. I tried to put it in a for statement but it's telling me there are 0 files.

What's wrong with this command?

Code:
for file in *.txt; do find /dir1/dir2/ -prune -type f -mtime +1 -exec ls -l $file {} \;; done | wc -l

There are in fact files older than 1 day.

---------- Post updated 07-06-10 at 10:59 AM ---------- Previous update was 07-05-10 at 03:38 PM ----------

What am I doing wrong with this command please?

Code:
for file in *.txt; do find /dir1/dir2/$file -prune -type f -mtime +1 -exec ls -l {} \;; done | wc -l

Keeps telling me arg list too long.

---------- Post updated at 11:10 AM ---------- Previous update was at 10:59 AM ----------

I got it to work.

Code:
for file in *.txt; do find /dir1/dir2/$file -prune -mtime +3 -exec echo {} \;; done | wc -w



---------- Post updated at 11:34 AM ---------- Previous update was at 11:10 AM ----------

scratch that ... still giving the same error:

Code:
bash: /usr/bin/find: The parameter or environment lists are too long

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Move a TXT file greater or equal 355 MB with its corresponding .LST file

Good morning, i need your help please I need to move a .TXT file greater or igual 355 MB and its correspondent .LST file in a non recursive way The operating system is: uname -a SunOS server01c 5.10 Generic_144488-01 sun4u sparc SUNW,SPARC-Enterprise For example: rw-r--r-- 1 xptol ... (8 Replies)
Discussion started by: alexcol
8 Replies

2. UNIX for Beginners Questions & Answers

Compare first column from two csv files with greater than or equal, and less than

I have two csv files of different sizes. The output file needs to have file1 contents on top of file2 contents where file2 col1 is >= to file1 col1, and file2 col1(same value) is < file1 col1 (next value). So basically, some file2 rows will be matched to the same file1 row because it is the closet... (7 Replies)
Discussion started by: aachave1
7 Replies

3. Shell Programming and Scripting

Find and substitute if greater than.

I have large config-files for an application. The lines have different structure, but some of them contains the parameter 'TIMEOUT=x', where x is an numeric value. I want to change the value for that specific paramater if the value is greater than a specific value (got that?). The timeout-parameter... (3 Replies)
Discussion started by: useless
3 Replies

4. Shell Programming and Scripting

Please help list/find files greater 1G move to different directory

I have have 6 empty directory below. I would like write bash scipt if any files less "1000000000" bytes then move to "/export/home/mytmp/final" folder first and any files greater than "1000000000" bytes then move to final1, final2, final3, final4, final4, final5 and that depend see how many files,... (6 Replies)
Discussion started by: dotran
6 Replies

5. Shell Programming and Scripting

Find files greater than a particular date in filename.

I need a unix command which will find all the files greater that a particular date in the file name. say for example I have files like(filenaming cov : filename.YYDDMMSSSS.txt) abc.201206015423.txt abc.201207013456.txt abc.201202011234.txt abc.201201024321.txt efg.201202011234.txt... (11 Replies)
Discussion started by: lijjumathew
11 Replies

6. Shell Programming and Scripting

find greater than value

Hi I want to find greater than and min value. dategrep() { varlinenum=$1 varSESSTRANS_CL="$(egrep -n "<\/SESSTRANSFORMATIONINST>" tmpsess9580.txt | cut -d":" -f1)" echo $varSESSTRANS_CL } dategrep 8 Output of the above command is: I want to find out greater than 8 and... (9 Replies)
Discussion started by: tmalik79
9 Replies

7. UNIX for Dummies Questions & Answers

How do I find files which are older than 30 days and greater than 1GB

Hi All, I know the separate commands for finding files greater than 30 days and finding files greater than 1GB. How do I combine these two commands? Meaning how do I find files which are > 1GB and older than 30 days? ;) (4 Replies)
Discussion started by: Hangman2
4 Replies

8. Shell Programming and Scripting

Find image greater than x pixels?

Hi Guys, I have a little problem, was wondering if anyone had any experience with this? I am using imagemagick to remove whitespace from images, however some images are corrupt and the server hangs and eventually crashes because imagemagick doesnt know what to do, even though I have set the... (4 Replies)
Discussion started by: mikemeadeuk
4 Replies

9. Shell Programming and Scripting

Problem with Greater Than Or Equal To

BASH problem with IS GREATER THAN OR EQUAL TO. I have tried a dozen variations for this IF statement to work with IS GREATER THAN OR EQUAL TO. My code below WORKS. array=( $( /usr/bin/sar -q 1 30 |grep Average |awk '{print $2,$3}' ) ) nthreads="${array}" avproc="${array}" if && ; then ... (6 Replies)
Discussion started by: diex
6 Replies

10. Shell Programming and Scripting

Important finding --- find files greater than 1 MB

as we can find file greater than 1 MB with find command as: find /dir -name '*' -size +1M find /dir/* -name '*' -size +1M but wats its doing is , its finding files only in current directory not in sub-directories. i want files from sub-directories too. Please help... Thanx in... (3 Replies)
Discussion started by: manoj_dahiya22
3 Replies
Login or Register to Ask a Question