[Novalug] changing file names
Jon LaBadie
novalugml@jgcomp.com
Mon Nov 23 23:52:50 EST 2009
On Mon, Nov 23, 2009 at 10:39:33PM -0500, Nino Pereira wrote:
> List,
>
> over the years I have seen various ways to change file names
> in a directory, e.g., from lower case to upper case or vice
> versa, in some automatic way. Unfortunately, I can't remember
> which program to use with this: awk? , sed? the mind boggles.
>
> I have a long list of files without extensions. I want to
> add an extension (like .pdf or .jpg or .gif). How do you do that?
>
Only way is to do them one at a time. Either you do the loop
or some command does it for you. I see linux has a "rename"
command but it doesn't seem to have the capability to add
an extension. Change one to another, but not add one.
I tend to shell program a loop at the command line. But before
executing the loop with an actual "mv" command, I prepend the
command with an "echo" to see what it will do. For example,
assuming you are renaming everything in a directory:
$ for f in *
> do
> echo mv $f $f.jpg
> done
mv abc abc.jpg
mv def def.jpg
mv foo foo.jpg
$
Assuming I'm happy with the list of commands that will execute,
I use command line editing to recall the last command, delete
the word "echo", and re-execute the loop.
Jon
--
Jon H. LaBadie jon@jgcomp.com
JG Computing
12027 Creekbend Drive (703) 787-0884
Reston, VA 20194 (703) 787-0922 (fax)
More information about the Novalug
mailing list