find/if statement not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find/if statement not working
# 8  
Old 12-15-2005
Well,
DELFILE_1=abc1.txt.$DATE1*
can have a variety of effects depending on whether or not any files in the current directory happen to match the pattern. If they do, the pattern will be replaced with the list of matching filenames. So you might want to make sure that you are in the same directory as the script when you run the above command.

But of course, if this had been the problem, it would have been exposed when you followed my advice:
"geomonap, do stuff like:
echo DELFILE_2= $DELFILE_2
just before your find statement so you can see what is happening."
so that can't be it. And so I'm not sure what to tell you. Smilie
# 9  
Old 12-15-2005
Quote:
Originally Posted by Perderabo
Getting closer Smilie

-mtime 2 means exactly 2 days old (i.e. exactly 60*60*24*2 = 172,800 seconds old)
-mtime -2 means less than 2 days old
-mtime +2 means more than 2 days old
Should have been more specific. +n means files that are n+1 days old or older.
# 10  
Old 12-16-2005
Quote:
Originally Posted by blowtorch
Should have been more specific. +n means files that are n+1 days old or older.
2 days and 1 second is more than 2 days. The file does not need to be a full 3 days old to match -mtime +2.
# 11  
Old 12-16-2005
I have a question then! What will '-mtime 0', '-mtime +0' and '-mtime -1' give? Will the last two be the same?

I have used '-mtime +0' to find files older than 24 hours. By that reckoning, I should get files older than 48 hours with '-mtime +1', and files older than 72 hours with '-mtime +2'.

P.S. I am using hours here to avoid confusion with 'days'. Since we think of a day as time from 00:00 to 23:59, it can be a bit confusing.
# 12  
Old 12-16-2005
Quote:
Originally Posted by blowtorch
I have a question then! What will '-mtime 0', '-mtime +0' and '-mtime -1' give? Will the last two be the same?
Using -mtime +0 and -mtime -1 would not be the same

-mtime 0 - would display files for which 24 hrs is not completed (exactly 0 days -- so it should be less than 24 hrs)

-mtime +0 - would display all the files (more than 0 days --- all the files timestamp would fall under this )

-mtime -1 - would display files for which 24 hrs is not completed ( less than 1 day -- so less than 24 hrs )

using -mtime 0 and -mtime -1 would give the same listing
# 13  
Old 12-16-2005
Actually, according to posix, we are all wrong. Smilie

Quote:
-ctime n
The primary shall evaluate as true if the time of last change of file status information subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n.
By this definition:
Code:
0 days in seconds:       0  -   86399
1 day in seconds:    86400  -  172799
2 days in seconds:  172800  -  259159

This means that "-mtime 0" and "-mtime -1" would be the same and this is the only pair of specs that should behave identically.

Note that "find" can take a while to run, so you measure based on when "find" started. This means that if a file was created several seconds after find started, it should match "-mtime -0".

I'm not sure that all versions of find adhere strickly to this definition of time. I guess I'll do some testing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read statement not working

hello guys, i am having the below piece of code error () { echo"Press y /n" read ans case $ans in y) main;; n) exit esac } In the abve code, read statement is not working i.e not waiting for user to enter input. ,i tested exit status its 1. could anyone help me to do this ... (11 Replies)
Discussion started by: mohanalakshmi
11 Replies

2. Shell Programming and Scripting

Case statement not working as expected

case "$freq" in " Hz") low=250; high=550;; "8 Hz") low=250; high=1000;; " Hz") low=400; high=1000;; "63 Hz") low=550; high=1000;; " Hz") low=400; high=550;; ... (2 Replies)
Discussion started by: Michael Stora
2 Replies

3. Shell Programming and Scripting

If statement is not working in KSH

#! /bin/ksh rm -f ./xyz file --- this line is working // Below any if stmt is not working. if then echo " blah blah " fi or I replaced above if with if then echo "dir exists" fi This is also not working. I am new to KSH. So can someone help why if stmt is not... (31 Replies)
Discussion started by: saggy9583
31 Replies

4. Shell Programming and Scripting

Cshell if statement not working

Hi .I am trying to check the first arguments =-s and the third =-d,but it doesnt work ,any idea why It gives me if: Missing file name Thanks #case -s and files if( $1 == "-s" && $3 != "-d" ) then echo "case s" endif (1 Reply)
Discussion started by: lio123
1 Replies

5. Shell Programming and Scripting

If statement is not working.

Hi. With the help of this group I have created a shell script to find the factorial of a number. OK. Then I got wild.;) I tried to put in a check to make sure the entry is a number. read num If )) then echo "This is not a valid number. Try again." fi while (( $var <= $num)) more... (5 Replies)
Discussion started by: Ccccc
5 Replies

6. UNIX for Dummies Questions & Answers

if statement not working as desired

Hello all, I am trying to write a post-commit hook script using bash script. What I am trying to do here is: Developers check in their files to a branch. I check the repository and based on the commit I email QA people. QA verifies and moves the files to a prod branch and email is sent... (1 Reply)
Discussion started by: kminkeller
1 Replies

7. Shell Programming and Scripting

Read statement not working in a script

I have a script consisting of certain functions whose input is a file at same location. In that file i have written the name of anothe file at same location. The third file contains a word which act as a function in the first script.Let me give an example i have a scrip file say 1.sh in which i am... (7 Replies)
Discussion started by: sumitdua
7 Replies

8. Shell Programming and Scripting

read statement not working in a function

Pls this is emergency.I have written a script which is taking input from another script. and the contents of my second script are acting as functions to my main script.Now the problem is that in one of the functions i want the script ececution to stop and start when user enters any character r... (2 Replies)
Discussion started by: sumitdua
2 Replies

9. UNIX for Dummies Questions & Answers

until statement not working

im trying to write an until statement which dont go onto the next stage until the user inputs a certain phrase. It is then stored in an array. Ive come up with this code so far but its not working and i dont know why. read in1 until do echo "Incorrect, try again" ... (2 Replies)
Discussion started by: strasner
2 Replies

10. Shell Programming and Scripting

If statement not working

I understand this question probably poses some child like stupidity, but I can't get this if statement to work for love or money. #!/bin/ksh echo "Input either 1 or 2" read Num if ; then echo "Message 1" if ; then echo "Message 2" else echo "false" fi $ ksh decisions Input either 1... (6 Replies)
Discussion started by: Hazmeister
6 Replies
Login or Register to Ask a Question