Linux/Unix – Renaming Multiple Files with the Same Extension.

To give a different file name extension to a group of files that share the same file name extension, use chcase with the `−x’ option for specifying a Perl expression; give the patterns to match the source and target files as a quoted argument. For example, you can rename all file names ending in `.htm’ to end in `.html’ by giving `s/htm/html/’ as the expression to use.

To rename all of the files in the current directory with a `.htm’ extension to `.html’, type:

$ chcase −x ‘s/htm/html/’ ‘*.htm’

By default, chcase will not overwrite files; so if you want to rename `index.htm’ to `index.html’, and both files already exist in the current directory, the above example will do nothing. Use the `−o’ option to specify that existing files may be overwritten.

To rename all of the files in the current directory with a `.htm’ extension to `.html’ and overwrite any existing files, type:

$ chcase −o −x ‘s/htm/html/’ ‘*.htm’ 


Advertisements

About msotela

This blog is for anyone who wants to access the power of a Linux system as a systems administrator or user. You may be a Linux enthusiast, a Linux professional, or possibly a computer professional who is increasingly finding the Windows systems in your data center supplanted by Linux boxes.

Posted on March 16, 2009, in Unix/Linux. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: