UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 18.12 Renaming a List of Files Interactively Chapter 18
Linking, Renaming, and Copying Files
Next: 18.14 Relinking Multiple Symbolic Links
 

18.13 One More Way to Do It

I couldn't resist throwing my hat into this ring. I can imagine an unsophisticated user who might not trust himself to replace one pattern with another, but doesn't want to repeat a long list of mv commands. Here's a simple script (1.5) that takes a list of filenames (perhaps provided by wildcards) as input, and prompts the user for a new name for each file:




-n 


#!/bin/sh
# Usage: newname files
for x 
do
    echo -n "old name is $x, new name is: "
    read newname
    mv "$x" "$newname"
done

For example:

touch 




% touch junk1 junk2 junk3
% newname junk*

old name is junk1, new name is: test1
old name is junk2, new name is: test2
old name is junk3, new name is: test3

This script is so simple, it's not included on the disc. I just thought I'd throw it in to demonstrate that there's more than one way to do it, even if you aren't using Perl (18.10).

- TOR


Previous: 18.12 Renaming a List of Files Interactively UNIX Power ToolsNext: 18.14 Relinking Multiple Symbolic Links
18.12 Renaming a List of Files Interactively Book Index18.14 Relinking Multiple Symbolic Links

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System