[nflug] file name extensions
Jesse Jarzynka
denisesballs at thecybersource.com
Thu Nov 16 18:22:25 EST 2006
Mark T. Valites wrote:
> On Thu, 16 Nov 2006, Robert Meyer wrote:
>
>> Not necessarily so. I made that as a general case. There are a
>> zillion ways to get a list of files into that command. The
>> implementation was left as an exercise for the reader :-)
>>
>> Hmmm.. OK, guys. How many ways are there to do this in Unix? I'll
>> bet we can come up with at least five or six. Take into account the
>> fact that there could be spaces in the files and we want to traverse
>> a directory, recurively. You're allowed to use any shell you want,
>> including perl. Points awarded for snarky, weird or just plain
>> bizarre methods. It has to work properly.
>>
>> Here is my contribution:
>> #!/bin/bash
>> for name in `find $1 -type f`; do
>> mv "$name" "${name}.sxw"
>> done
>
> No, the example above would be the perfect example for useless use of
> a for loop, regardless of how "generic" it was designed or how well it
> "recurively" traversed a directory. The for loop needlessly iterates
> over a list generated by find when find could do everything needed in
> one shot.
>
> It also could potentially suffer from a limit of the length of command
> the shell can handle.
>
> A simpler solution that explicitly lists the source and destination
> files names would be:
>
> $ find /path -type f -exec mv {} {}.sxw \;
>
> Better yet:
>
> $ find /path -type f -exec mv {}{,.sxw} \;
>
> _______________________________________________
> nflug mailing list
> nflug at nflug.org
> http://www.nflug.org/mailman/listinfo/nflug
>
Hasn't anyone ever heard of rename???
$ rename -s/.whatever/.sxw/ *
-Jesse
_______________________________________________
nflug mailing list
nflug at nflug.org
http://www.nflug.org/mailman/listinfo/nflug
More information about the nflug
mailing list