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

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

Post by usene » Wed, 19 Oct 2005 05:03:31



One other minor point - if your filenames contain "goofy" characters it
can confuse the shell. Filenames can contain "&" and ">" and
whitespace and linefeeds (really!) and all sorts of other things that
are meaningful in shell commands.

It's a possible security risk also. If you have a file named "rm -rf
/&" (or a hax0r is able to create such a file) then you might regret
running this script.
 
 
 

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

Post by Tad McClel » Wed, 19 Oct 2005 07:44:59


Which will, of course, not do the right thing with something like:

/usr/home/somedir

...


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

 
 
 

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

Post by dkcomb » Wed, 19 Oct 2005 13:23:22

In article < XXXX@XXXXX.COM >,

...

Yeah, neat script!

I've tried it, and it seems to work just fine!

David
 
 
 

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

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

In article < XXXX@XXXXX.COM >,



I'm (perpetually) new at this stuff -- perhaps you could please
lay that out in a bit more detail?

Like, how does a filename get "executed" or "evaled" in that script?

(Looks like it's something much worth understanding!)

Thanks,

David
 
 
 

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

Post by dkcomb » Wed, 19 Oct 2005 13:54:25

In article < XXXX@XXXXX.COM >,


Well, my egrep found *lots* of *lines* -- but then when I
looked at just the file-*names*, it wasn't so bad.

(If it did turn out to be "a gillion", then I guess that
xargs would make it ok?)

David
 
 
 

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

Post by dkcomb » Wed, 19 Oct 2005 13:56:03


Thanks for the warning. Will try to be alert to it.

David
 
 
 

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

Post by Joe Smit » Wed, 19 Oct 2005 21:13:37


If you modify the script so that it can handle file names with
embedded spaces, that will take care of most of the metacharacters.

#!/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

-Joe
 
 
 

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

Post by usene » Thu, 20 Oct 2005 03:18:01


There's a command that says:
$file.new && mv $file.new $file

Suppose you had a file on your system named "rm -rf /&". A copy of
that file gets created named "rm -rf /&.new" When you do the test, it
becomes:
rm -rf /&.new && mv rm -rf /&.new rm -rf /&

The "&" tells the shell to take the preceeding command and run it in
the background. So the shell sees up to the first "&" and runs
everything in front of it. oops. the part behind the first ampersand
is still a valid shell command, but won't execute unless you happen to
have a file named ".new"