UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 18.11 Renaming Files with ren Chapter 18
Linking, Renaming, and Copying Files
Next: 18.13 One More Way to Do It
 

18.12 Renaming a List of Files Interactively

Article 18.9 shows how to rename a set of files, like changing *.new to *.old. Here's a different way, done from inside vi. This gives you a chance to review and edit the commands before you run them. Here are the steps:


& 
$ 

% vi   Start vi without a filename
:r !ls *.new   Read in the list of files, one filename per line
:%s/.*/mv & &/ Make mv command lines
:%s/new$/old/   Change second filenames; ready to review
:w !sh   Run commands by writing them to a shell
:q!   Quit vi without saving

If you've made an alias (10.2) for ls that changes its output format, that can cause trouble here. If your alias gives more than a plain list of filenames in a column, use !/bin/ls instead of just !ls.

- JP


Previous: 18.11 Renaming Files with ren UNIX Power ToolsNext: 18.13 One More Way to Do It
18.11 Renaming Files with ren Book Index18.13 One More Way to Do It

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