home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Unix Power ToolsUnix Power ToolsSearch this book

10.10. Renaming a List of Files Interactively

Section 10.9 shows how to rename a set of files, e.g., 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:

&& Section 34.10, $ Section 32.5

% vi                Start vi without a filename
:r !ls *.new        Read in the list of files, one filename per line
:%s/.*/mv -i &&/    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 your own version of ls that changes its output format, that can cause trouble here. If your version gives more than a plain list of filenames in a column, use!/bin/ls instead of just !ls.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.