[nflug] file name extensions

Robert Meyer meyer_rm at yahoo.com
Thu Nov 16 14:54:21 EST 2006


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 :-)

Looks like I had to come up with a more specific case.

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

Cheers!

Bob

----- Original Message ----
From: Mark T. Valites <mark-nflug at valites.net>
To: nflug at nflug.org
Sent: Thursday, November 16, 2006 2:10:45 PM
Subject: Re: [nflug] file name extensions

On Thu, 16 Nov 2006, eric wrote:

> How would I recurse into sub directories(I'm in bash)
>
> Robert Meyer wrote:
>
>> in bash:
>> for name in `ls <directory of files`; do

Randal Schwartz would probably have a couple things to say if he saw the 
line above:

http://partmaps.org/era/unix/award.html#ls

In addition, files with spaces in their name would cause problems, and as 
eric writes, it doesn't take into consideration directories.

You probably want to use the 'find' command with the 'exec' arg with 
either mv or the 'rename' utility.

_______________________________________________
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