How to determine which directory is older

How to determine which directory is older

Post by lanem195 » Thu, 04 May 2000 04:00:00



Greetings,
I am trying to write a script that will check to see if one
directory is older than another, then do something.  I have
tried:
NEW_PATCH=`ls -ld /apps/R_PATCHES |cut -c42-47`
OLD_PATCH=`ls -ld /apps/PATCHES |cut -c42-47`
echo $NEW_PATCH
echo $OLD_PATCH
#
if [ "$NEW_PATCH" -gt "$OLD_PATCH" ]
then
    echo "$NEW_PATCH is greater than $OLD_PATCH"
fi

This gives me the two dates, $NEW_PATCH = May  3  and $OLD_PATCH
= Mar 13, however the two dates in this form are
not "algebraically" different so nothing happens.  I can not see
how using the dates as a string would help either.  Is there a
function call that I can add to my script to change these dates
and if so what is the syntax, as I have not used functions?  Is
there a better way to find out if one directory is older than
another?
Any help that can be provided would be appreciated.
I thank you in advance.
Mark A. Lane

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!

 
 
 

How to determine which directory is older

Post by Matthew Land » Thu, 04 May 2000 04:00:00



> Greetings,
> I am trying to write a script that will check to see if one
> directory is older than another, then do something.  I have
> tried:

Use the -t flag for ls to find the files in order of age, if all
you wanted was the newest (or oldest) directory.

newestfile=`ls -td /apps/R_PATCHES /apps/PATCHES |line`

echo "Newest file/directory is: $newestfile"

 - Matt

--
_______________________________________________________________________

   << Comments, views, and opinions are mine alone, not IBM's. >>

 
 
 

How to determine which directory is older

Post by Dan Merc » Thu, 04 May 2000 04:00:00




> Greetings,
> I am trying to write a script that will check to see if one
> directory is older than another, then do something.  I have
> tried:

You don't say what shell you are using.  Bash2, ksh and zsh have the -nt
operator for conditional expressions (if this is a linux distro, bash 2.x
may have been shipped as bash2).

   if [[ $NEW_PATCH -nt $OLD_PATCH ]]

If you are using the original bourne shell,  then use ls

   for newer in `ls -dt $NEW_PATCH $OLD_PATCH`;do break;done

--
Dan Mercer

> NEW_PATCH=`ls -ld /apps/R_PATCHES |cut -c42-47`
> OLD_PATCH=`ls -ld /apps/PATCHES |cut -c42-47`
> echo $NEW_PATCH
> echo $OLD_PATCH
> #
> if [ "$NEW_PATCH" -gt "$OLD_PATCH" ]
> then
>     echo "$NEW_PATCH is greater than $OLD_PATCH"
> fi

> This gives me the two dates, $NEW_PATCH = May  3  and $OLD_PATCH
> = Mar 13, however the two dates in this form are
> not "algebraically" different so nothing happens.  I can not see
> how using the dates as a string would help either.  Is there a
> function call that I can add to my script to change these dates
> and if so what is the syntax, as I have not used functions?  Is
> there a better way to find out if one directory is older than
> another?
> Any help that can be provided would be appreciated.
> I thank you in advance.
> Mark A. Lane

> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
> The fastest and easiest way to search and participate in Usenet - Free!

Opinions expressed herein are my own and may not represent those of my employer.
 
 
 

How to determine which directory is older

Post by lanem195 » Fri, 05 May 2000 04:00:00


Thanks Matt and Dan, both of you pointed me in the right
direction.

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!

 
 
 

1. Need help doing a find in current directory only of zero byte file that is older that is older than 10 minutes and move it to a subdirectory off the current directory

Need help doing a find in current directory only of zero byte file that
is older that is older than 10 minutes and move it to a subdirectory
off the current directory.

So far I have this:

find . -size 0c -exec mv {} /xxx/xxxxxx/xxx/error \;&

this is working but then when i run that, it goes to the subdirectories
as well, which I don't want, and it doesn't do the check for files
older than 10 minutes.  I only want to do a find on the current
directory, no subdirectories...and I want to only move a 0 byte file
that has been inactive for 10 minutes.  I am using Solaris 8 and its
older filesystem.

I tried prune, mindepth, etc with no success, but I could be using them
wrong....also tried -mmin +10 but seemed to not have the syntax right
with that either...so need help!

2. fdisk with extended IDE drive

3. How to determine if I am running libc.so.5

4. Anyone ever made their own device driver for Linux?

5. ncftp tries downloading older files, older than specified with -n

6. Hyper terminal kind of tools

7. How Do I Determine What Shell I am Using?

8. How to mount a linux directory (ReadHat 5.1) to FreeBSD 3.0's file system?

9. Determining whether I am using shared text segments under SVR4

10. "find"ing directories older than 7 days old.

11. how to remove directories older than 1 hour

12. Directory / files removal older than certain time

13. Need help to tar files in a directory older(creation date) than 45 days old