[nflug] file name extensions

Mark T. Valites mark-nflug at valites.net
Fri Nov 17 12:07:16 EST 2006


Check the "Brace Expansion" section of your favorite shell manpage for 
details.

Some quick things that might illustate what it's doing:

$ echo {one,two,three}
$ touch one
$ mv {one,two}
$ mv two{,-new_end}
$ mv two{-new_end,}
$ ls -l two*

On Fri, 17 Nov 2006, eric wrote:

> I have question :)
>
>
> $ find /path -type f -exec mv {}{,.sxw} \;
>
>
> in this command I was able to find out what everything was doing except
> the comma inbetween { and .sxw
> is it doing recursion?
>
>
> 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
>
>
> _______________________________________________
> nflug mailing list
> nflug at nflug.org
> http://www.nflug.org/mailman/listinfo/nflug
>
_______________________________________________
nflug mailing list
nflug at nflug.org
http://www.nflug.org/mailman/listinfo/nflug



More information about the nflug mailing list