Rename and Copy Files Easily in Your Text Editor
Renaming and copying files in bulk has never been quite as easy as it should be on Linux. If you're looking to make changes to a number of files in a hurry, check out renameutils, a set of utilities that will make renaming files as easy as using your favorite text editor.Renameutils is aptly named. The easy-to-use collection of utilities makes renaming files as easy as using your favorite text editor.
Say you have a directory with 500 files that follow a standard naming scheme and you want to change the names quickly or copy the files quickly. It's a chore with
cp. You can use standard *nix utilities to do it with a pipeline and practice, or you can download a few GUI tools for renaming files in batches and a couple of command-line utilities. However, if you're like many system administrators, what could be better than using a text editor to make the changes?
The renameutils will let you do just that. This project has five programs that make renaming files much easier. The primary utilities are
qcp. As the names suggest,
qmv is for moving files and
qcp is for copying.
Here's how they work. Running
qmv in a directory will display all the filenames in the directory in two columns in your text editor of choice. Edit the filenames on the right-hand side, and then save and exit the editor.
qmv will then apply the changes to the files. You can use the standard search-and-replace function in your favorite text editor to quickly make changes. (Hence the "q" in the name.) The same thing works with
qcp, of course, but it makes copies with the new filenames instead of moving the files.
The first time or two you use the utility, I'd recommend either practicing on some temporary files or using the
--dummy option, which tells you what would be done without making any changes.
Want to make a lot of changes to files in subdirectories? Use the
-R option. You can also pass filenames to the utilities, so
qmv *.png would operate only on files with .png extension. If you want to operate on "hidden" files, use the
If you're particularly lazy, I mean efficient, you can use the
icp utilities. While the
qcp utilities are meant for bulk operations, the
icp tools work with just one file. Type
imv filename (or
icp filename), and you will be prompted to edit the filename. If you want to edit just the file extension (which I do pretty often when authors send an HTML document labeled .txt), this saves a few precious keystrokes. Yes, every bit really does add up.
deurlname. This handy little utility lets you remove annoying characters in filenames that are a result of being grabbed by URL. For example, the
%20, which is inserted where a space should be in a filename if you grab it via HTTP.
You should be able to find the renameutils for most Linux distros, or grab the source code from the project site. The tools are written by Oskar Liljeblad. They are available under the GPLv3 or later. Check the man pages as well, as there is an interactive mode and a number of other options for advanced usage if you really want to become a renaming power user.
Joe 'Zonker' Brockmeier is a freelance writer and editor with more than 10 years covering IT. Formerly the openSUSE Community Manager for Novell, Brockmeier has written for Linux Magazine, Sys Admin, Linux Pro Magazine, IBM developerWorks, Linux.com, CIO.com, Linux Weekly News, ZDNet, and many other publications. You can reach Zonker at email@example.com and follow him on Twitter.