making same change to *lots* of files, *without* date changed

making same change to *lots* of files, *without* date changed

Post by dkcomb » Tue, 18 Oct 2005 14:27:28



Well, it's time to bite the bullet, and quit fighting
the idea (requirement?) that "/home" isn't for my own
use, but for the automounter's.

Way back with sunos (before solaris), use rooted a lot
of our stuff at /home, and refer to it throughout our
programs.

But solaris says no can do, unless you hack the automounter
files.

Well, the time has come to modify several hundred files,
changing every /home to /myhome.

But doing that will *** up the creation dates of the
files, on which I rely to remind me what I've been
working on recently.

Since I want to make this change to just about EVERYTHING,
I think it best if the dates do NOT change.

So, my question: how would *you* accomplish this task?

(maybe via a oneliner, the argument being a list of
the files that need this minor change?)

Yes, I've seen the faq, but before I try that,
I'd ask here if someone had already doine something
like this.

(Plus knew the dangers involved of dateless-hacking.)

Thanks!

David
 
 
 

making same change to *lots* of files, *without* date changed

Post by A. Sinan U » Tue, 18 Oct 2005 14:43:00


...


Process files one by one. First stat the file, and save the result of
the stat call, then touch the newly created file with the saved stat
information.

You can use either the touch command line utility or File::Touch

<URL: http://www.yqcomputer.com/ ~nwetters/File-Touch-0.01/>

Sinan
--
A. Sinan Unur < XXXX@XXXXX.COM >
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.yqcomputer.com/ ~tadmc/clpmisc/clpmisc_guidelines.html

 
 
 

making same change to *lots* of files, *without* date changed

Post by teste » Tue, 18 Oct 2005 15:09:29


I think you can copy files from /home to /myhome with -p option! explore
man cp

~ tester
 
 
 

making same change to *lots* of files, *without* date changed

Post by John W. Kr » Tue, 18 Oct 2005 15:28:25


AFAIK Unix doesn't record the creation dates of files anywhere.



man tar
man cpio



John
--
use Perl;
program
fulfillment
 
 
 

making same change to *lots* of files, *without* date changed

Post by Tinti » Tue, 18 Oct 2005 18:24:12


Only if you have a need for automounter.


Or simply disable automounter.


No such thing as a creation date in Unix. You probably meant last
modification date.


You certainly could do it in Perl, however it's just as easy with simple
Unix tools (my example references Perl to make it vaguely relevant to this
group), eg:

#!/bin/sh
for file in *.sh
do
perl -pe 's:/home:/myhome:g' $file >$file.new && touch -r $file
$file.new && mv $file.new $file
done
 
 
 

making same change to *lots* of files, *without* date changed

Post by dkcomb » Wed, 19 Oct 2005 02:21:22

In article <XtH4f.8$ XXXX@XXXXX.COM >,


...

Copy the files? Really?

Can't I just rename (mv) the current (via hack to automoount) /home
to /myhome?

But that isn't the problem -- the problem is how to change all
the "/home[^a-zA-Z-]" to "/myhome" -- *within* those files.

david
 
 
 

making same change to *lots* of files, *without* date changed

Post by dkcomb » Wed, 19 Oct 2005 02:26:47

In article < XXXX@XXXXX.COM >,


One by one, *by hand*?

Gee, I was hoping for a (if trustworthy!) single cmd based on something
like this:

perl -i.bak -pe 's/(?:\015)?\012/\015/g' filenames

, but with a "don't modify the date/times" (somehow) added in.


Thanks,

David


PS: FEATURE-SUGGESTION: if not already existing, then a *new*
option for just that purpose?
 
 
 

making same change to *lots* of files, *without* date changed

Post by Paul Lall » Wed, 19 Oct 2005 02:40:51


You make it sound like someone told you to dig into your chipset and
start modifying the bits.

Can you explain how File::Find and File::Copy do not suit your needs?


I don't know what you think that does, but I'm willing to bet it
doesn't.


File::Copy's move() and copy() routines do not modify the last modified
time.


I still don't know what "new option" you're talking about, but in Perl,
we typically call new features "modules". You are, of course, welcome
to contribute any such thing you find useful to the rest of the Perl
community.

Now, taking a step back, perhaps I've misunderstood what you're asking
for, but why do you believe this needs to be done in Perl at all? What
is wrong with simply:

cp -Rp /home/* /myhome/

?

Paul Lalli
 
 
 

making same change to *lots* of files, *without* date changed

Post by xhoste » Wed, 19 Oct 2005 02:45:56


With utime.


There are lots of faqs. Which faq are you referring to?


Not all combinations of OS/FS/mount options/phase of moon allow you to
back-date files. So test your program out on test files on the same
mount-point your real files, otherwise you may permently lose your date
information if something goes wrong. (Or backup your files in
data-preserving way before doing anything)


Xho

--
-------------------- http://www.yqcomputer.com/
Usenet Newsgroup Service $9.95/Month 30GB
 
 
 

making same change to *lots* of files, *without* date changed

Post by xhoste » Wed, 19 Oct 2005 02:48:15


They also don't modify the contents of the file, which the OP wants to do.

Xho

--
-------------------- http://www.yqcomputer.com/
Usenet Newsgroup Service $9.95/Month 30GB
 
 
 

making same change to *lots* of files, *without* date changed

Post by dkcomb » Wed, 19 Oct 2005 02:51:45

In article <15K4f.974$ XXXX@XXXXX.COM >,





AH HA! COOL -- THANK YOU!

Please, (other) perl/unix gurus, visually/mentally verify the
above nifty-trick` (obvious only once you see it!) and
RSVP here -- before I go try the thing!

(Of course I'll try it on some test files first --
but maybe some of you will see some inherent problems,
eg if a file has certain attributes ...?)


THANKS TO ONE AND ALL!

David

PS: again, please say something, pos or neg, about
the above super-concise scheme.

And thanks for *that*, too!

D.
 
 
 

making same change to *lots* of files, *without* date changed

Post by Paul Lall » Wed, 19 Oct 2005 03:04:54


Ahhh, that's the part of the OP's requirements that I didn't
understand. Thanks, Xho.

Paul Lalli
 
 
 

making same change to *lots* of files, *without* date changed

Post by A. Sinan U » Wed, 19 Oct 2005 03:14:27


I don't understand what you don't understand. I am assuming you have
some idea how to get (in Perl) a list of files which need to be changed.
Open each file in that list, save the stat information, open a file to
write to, write the changed contents to that file, and, after closing
that file, touch with the cached stat information.

It is possible to write that script in the time it took you to come up
with this genius response.

Alternatively, you can use the shell script provided by Tintin.
Personally, that's what I would have done, but you asked on a Perl
group.

Sinan

--
A. Sinan Unur < XXXX@XXXXX.COM >
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.yqcomputer.com/ ~tadmc/clpmisc/clpmisc_guidelines.html
 
 
 

making same change to *lots* of files, *without* date changed

Post by Tad McClel » Wed, 19 Oct 2005 03:17:58


I'll assume you meant "modification timestamp" where you
said "creation date".




What will it do to a directory named

/homebase

??

A: change it to

/myhomebase


So, we'd better make that:

s:/home/:/myhome/:g


--
Tad McClellan SGML consulting
XXXX@XXXXX.COM Perl programming
Fort Worth, Texas
 
 
 

making same change to *lots* of files, *without* date changed

Post by usene » Wed, 19 Oct 2005 04:55:39

> >#!/bin/sh



Only a minor point - if you have a "gillion" files, you may find that
the "*.sh" overflows your shell's command buffer, especially if the
filenames are long (depending on your OS).