How do I change a files's last modified date?

How do I change a files's last modified date?

Post by kev » Thu, 23 Dec 1999 04:00:00



Hi,

I am writing a script to do a backup of files. I need to get only files
which are newer than the last backup. Unfortunately I have deleted all
the .tar.Z files because they were huge files and they filled up the
disk. If I still had them I could work out which files I needed to
backup with...

find /dir/to/look/at -newer lastbackup.tar.Z

So, my solution is to create a dummy file called lastbackup, and set the
last modified time to, say, two weeks ago, then do my first
'incremental' backup, then 'touch' it after every backup.

How do I change the date on the file to two weeks ago today? Changing
the system's date then 'touch'ing the file is not an option.

thanks,

- Kev

 
 
 

How do I change a files's last modified date?

Post by Erhard Sieg » Thu, 23 Dec 1999 04:00:00



> Hi,
> I am writing a script to do a backup of files. I need to get only files
> which are newer than the last backup. Unfortunately I have deleted all
> the .tar.Z files because they were huge files and they filled up the
> disk. If I still had them I could work out which files I needed to
> backup with...
> find /dir/to/look/at -newer lastbackup.tar.Z
> So, my solution is to create a dummy file called lastbackup, and set the
> last modified time to, say, two weeks ago, then do my first
> 'incremental' backup, then 'touch' it after every backup.

You can do a

find /dir/to/look/at -mtime -14

the first time and then proceed the way you intended to do it.

Hope this helps,

Erhard

--
"Doubt is not a pleasant mental state, but certainty is a ridiculous one."
                                                                -Voltaire

 
 
 

How do I change a files's last modified date?

Post by kev » Thu, 23 Dec 1999 04:00:00




> > Hi,

> > I am writing a script to do a backup of files. I need to get only files
> > which are newer than the last backup. Unfortunately I have deleted all
> > the .tar.Z files because they were huge files and they filled up the
> > disk. If I still had them I could work out which files I needed to
> > backup with...

> > find /dir/to/look/at -newer lastbackup.tar.Z

> > So, my solution is to create a dummy file called lastbackup, and set the
> > last modified time to, say, two weeks ago, then do my first
> > 'incremental' backup, then 'touch' it after every backup.

> You can do a

> find /dir/to/look/at -mtime -14

> the first time and then proceed the way you intended to do it.

I just tried this, but it doesn't quite work as expected.

It looks like your example above will find files that were modified 14 days
ago, but won't catch files that were modified 13,12,10 days ago, or
yesterday!

I'm doing this in Perl, so it's easy enough to write a function which will do
-mtime -14, -mtime -12, etc, but there must be a more elegant solution?

- Kev

 
 
 

How do I change a files's last modified date?

Post by kev » Thu, 23 Dec 1999 04:00:00


Doh! (My brain's been working hard today, it's exhausted)
The answer was right under my nose all the time:

touch -at 199912081500

I _think_ '-at' are the correct options...

thanks,

- Kev




> > > Hi,

> > > I am writing a script to do a backup of files. I need to get only files
> > > which are newer than the last backup. Unfortunately I have deleted all
> > > the .tar.Z files because they were huge files and they filled up the
> > > disk. If I still had them I could work out which files I needed to
> > > backup with...

> > > find /dir/to/look/at -newer lastbackup.tar.Z

> > > So, my solution is to create a dummy file called lastbackup, and set the
> > > last modified time to, say, two weeks ago, then do my first
> > > 'incremental' backup, then 'touch' it after every backup.

> > You can do a

> > find /dir/to/look/at -mtime -14

> > the first time and then proceed the way you intended to do it.

> I just tried this, but it doesn't quite work as expected.

> It looks like your example above will find files that were modified 14 days
> ago, but won't catch files that were modified 13,12,10 days ago, or
> yesterday!

> I'm doing this in Perl, so it's easy enough to write a function which will do
> -mtime -14, -mtime -12, etc, but there must be a more elegant solution?

> - Kev

 
 
 

How do I change a files's last modified date?

Post by Art S. Kage » Thu, 23 Dec 1999 04:00:00


touch -r <reference file>  lastbackup  #Set time to that of <reference file>
touch 12080000 lastbackup              #Set time to 1999-12-08 00:00:00
touch 199912080102.03                  #Set time to 1999-12-08 01:02:03

See: man touch for the complete poop.

Art S. Kagel


> Hi,

> I am writing a script to do a backup of files. I need to get only files
> which are newer than the last backup. Unfortunately I have deleted all
> the .tar.Z files because they were huge files and they filled up the
> disk. If I still had them I could work out which files I needed to
> backup with...

> find /dir/to/look/at -newer lastbackup.tar.Z

> So, my solution is to create a dummy file called lastbackup, and set the
> last modified time to, say, two weeks ago, then do my first
> 'incremental' backup, then 'touch' it after every backup.

> How do I change the date on the file to two weeks ago today? Changing
> the system's date then 'touch'ing the file is not an option.

> thanks,

> - Kev

 
 
 

How do I change a files's last modified date?

Post by kev » Thu, 23 Dec 1999 04:00:00



> touch -r <reference file>  lastbackup  #Set time to that of <reference file>
> touch 12080000 lastbackup              #Set time to 1999-12-08 00:00:00
> touch 199912080102.03                  #Set time to 1999-12-08 01:02:03

Thanks, I've got it now. Now I'd like to know how I can get the whole thing
onto one command line :)

I want to take the output of:

find /data/carlingnet/docs -newer lastbackup

and pipe it (or redirect it) to the input of:

tar cvf incbak1.tar | compress

I've tried to pipe and redirect but it didn't work. How do I get it all on one
command line?

thanks,

- Kev

 
 
 

How do I change a files's last modified date?

Post by Paul Kimo » Fri, 24 Dec 1999 04:00:00



> I want to take the output of:

> find /data/carlingnet/docs -newer lastbackup

> and pipe it (or redirect it) to the input of:

> tar cvf incbak1.tar | compress

> I've tried to pipe and redirect but it didn't work. How do I get it all on one
> command line?

"tar cvf" doesn't do anything with its standard input.  It does write the
list of files to the standard output, but you are just compressing that to
the standard output of "compress".

Now, if the resulting command line is not too long, you can do

$ tar cvf incbak1.tar `find /data/carlingnet/docs -newer lastbackup`
(the shell will substitute the output of "some command" for
`some command`) and then
$ compress incbak.tar
(if that is what you mean to do).

If the resulting command line _is_ too long, then you will have to do
write the "find" output to a file and use the "tar" -T option, or try
something cagey like (untested!)
$ rm incbak1.tar && touch incbak.tar &&
  find /data/carlingnet/docs -newer lastbackup -print |
   xargs -r tar uvf incbak1.tar
(see the find, xargs, and tar documentation ...).

--

 
 
 

How do I change a files's last modified date?

Post by Erhard Sieg » Fri, 24 Dec 1999 04:00:00




>> You can do a

>> find /dir/to/look/at -mtime -14

>> the first time and then proceed the way you intended to do it.

> I just tried this, but it doesn't quite work as expected.
> It looks like your example above will find files that were modified 14 days
> ago, but won't catch files that were modified 13,12,10 days ago, or
> yesterday!

That would be if you write

find /dir/to/look/at -mtime 14
but not
find /dir/to/look/at -mtime -14

I tried it:
minas:/home/erhard # find . -mtime -3 -exec ls -ld {} \; |  cut -b 30- | tail
        6929 Dez 20 20:56 ./.netscape/preferences.js
       16384 Dez 20 20:35 ./.netscape/secmodule.db
         425 Dez 20 20:37 ./.netscape/history.list
      327680 Dez 20 20:56 ./.netscape/history.dat
        3842 Dez 20 20:56 ./.netscape/liprefs.js
        1043 Dez 23 18:46 ./.kderc
       20427 Dez 23 19:04 ./tmp1
           4 Dez 22 20:04 ./.kss-install.pid.minas
       28865 Dez 23 18:47 ./xmas1.JPG
        1045 Dez 22 19:34 ./.article.348~
minas:/home/erhard #    

Apearently it works on my system.

Erhard

--
"Doubt is not a pleasant mental state, but certainty is a ridiculous one."
                                                                -Voltaire