?
Solved

find command's newer option

Posted on 2005-05-11
4
Medium Priority
?
1,092 Views
Last Modified: 2013-12-27
Hi,

I have a directory user1 in which files get written continuously.
I want to list the "new" files that are in this directory based
on a reference file using find command.
Here's what I have been trying:

#!/bin/sh
ref_file=/export/home/user1/ref

fn()
{
while read file
do
find . \( -name $file -a newer $ref_file \) -print
done < list
}

fn
touch $ref_file

Here "list" is a text file which contains list of all files in the specified directory.
The problem is that whenever i create(touch) the $ref_file through the script
the find command does not find files newer than $ref_file while as if I do NOT
create the file ($ref_file) through the script and create it manually before executing the script, new files are found.

Basically, since the ref_file is being created just after any new file is written in the directory
the find command "fails" to recognize any new file. I have tried to "sleep 60" before creating the
reference file but of no avail.

BTW, in the find command how new is newer -is it based on seconds,minutes etc.

Any help would be highly appreciated.
rte
0
Comment
Question by:run_time_error
4 Comments
 
LVL 1

Expert Comment

by:solnpro
ID: 13981270
-newer file
      True if  the  current  file  has  been  modified  more recently than the argument file.

From what you describe, ref is being created after the files are written in the directory.  Therefore the current file will never have been modified more recently.

I took your example script above, added the missing "-" in front of newer, defined ref as being in the same directory, saved the script as finder.sh, and it seemed to work fine for this simple test...

> ls
file1      file2      finder.sh  list       ref
> cat list
file1
file2
> rm ref
> echo test > ref
> ./finder.sh
> touch file1
> ./finder.sh
./file1
> touch file2
> ./finder.sh
./file2
> ./finder.sh
> touch ref
> touch file1
> ./finder.sh
./file1

Can you be more specific about what isn't working?

Thanks,
<Solnpro>
0
 
LVL 38

Accepted Solution

by:
yuzh earned 750 total points
ID: 13983200
Modify your script to make it looks like:

#!/bin/sh
ref_file=/export/home/user1/ref
LIST=/path-to/list
fn()
{
cd /path-to/user1
while read file
do
find .  -name $file -a newer $ref_file  
done < $LIST
}

fn
touch $ref_file
exit

#END of script
0
 
LVL 48

Expert Comment

by:Tintin
ID: 13983392
Not related to touch and find, but why are you using a function that serves no purpose, or is this a very cut down script to demonstrate the problem?
0
 

Author Comment

by:run_time_error
ID: 13995883
this is a cut down script - trying to relate the problem with a example script.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question