[Chapter 18] 18.13 One More Way to Do It
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:39:10Z

#

| Chapter 18 Linking, Renaming, and Copying Files |

## 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

18.12 Renaming a List of Files Interactively |  | 18.14 Relinking Multiple Symbolic Links