Use rename to change multiple filenames

| 1 Comment

I {heart} UNIX! In addition to the 'find' commend, I just found another very useful command that is now my second favorite!


The rename command renames files according to a pattern, such as:

I needed to rename almost 800 files from a format like "2007_XXXXXXXXXXXXXX.php" to use a hyphen (dash) instead of the underscore after the year - such as "2007-XXXXXXXXXXXXXX.php". I did this with the following for each year (there's probably a way to rename all years at once, but I didn't have a backup and didn't want to screw it up):

rename 2007_ 2007- 2007*.php

which means "change the string 2007_ to 2007- in all filenames resulting from 2007*.php".

Worked like a charm!!!

I am not responsible for any problems you may encounter. Backup all files first.

1 Comment

Cheers for this, didn't realise the command existed! From looking at the man page it appears you can use the `-n` flag to preview the changes the command makes before applying them.

Leave a comment

Sketch of Cheryl

About Cheryl

Enjoys crocheting, gardening, cats, NASCAR (especially Tony Stewart and Kyle Busch!), reading, photography, snorkeling in Kailua-Kona with sea turtles, Sizzler's Mega Bacon Cheeseburgers, hot and iced decaf coffee, dark chocolate, color (yarn, fabric), playing around with web technologies - not necessarily in that order! Still very much a beginner with quilting, knitting, and sewing. Donates crocheted lap blankets.

List maker, detail-oriented, organized, leans heavily toward perfectionism. ISTJ. Libra.

January 2017

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Disclaimer: This is a personal website - my place of self expression. The views expressed are mine alone and do not necessarily reflect the views of my employer or any other organization I am a member of or affiliated with.
Creative Commons License
This blog is licensed under a Creative Commons License.
Powered by Movable Type 5.2.2

About this Entry

This page contains a single entry by Cheryl published on October 27, 2007 3:02 PM.

100020 miles was the previous entry in this blog.

The move to MT 4 so far is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Cat playing with strand of yarn.


Recent Comments

  • Matt Button: Cheers for this, didn't realise the command existed! From looking read more