Home > bash, shell scripting, tech > beautiful shell script – rename files with paths – man find

beautiful shell script – rename files with paths – man find

I’m in the process of converting a MCMS generated site over to php / unix environment and was suffering from the “default.htm” problem. So I needed to copy all the default.htm files to index.htm. Was sitting there playing with some shell scripting for a minute and then found this GREAT link: awesome one-liner:

for f in `find . -name '*replaceme.jpg'` ; do mv $f ${f/replaceme/withme}; done

Ok, so I had to see how this thing works… I’ve used bash for several years and never saw this ${f/x/y} syntax.. looking at the bash reference guide, it looks like “shell parameter expansion”. Very convenient.. if only I had read the manual sooner….

  1. June 16, 2008 at 12:50 am

    I’m just looking for a script that will take 2 arguments, and replace the first string in the filename with the second string. How hard is that??

  2. goemon
    July 17, 2008 at 10:53 am

    what abou the rename command?

  3. May 28, 2013 at 6:23 pm

    Hello, after reading this awesome article i
    am also happy to share my familiarity here
    with friends.

  4. August 16, 2013 at 10:36 am

    Luckily for you, I have discovered a way to permanently rid yourself of
    the red ring of death for good and it doesn’t involve sending your console away to Microsoft or pay for costly repairs. The game’s fourth campaign DLC, Tiny
    Tina’s Assault on Dragon Keep, released earlier this week. I didn”t believe it in the beginning, but when the 100 % free PSN codes worked, I was jumping vertical.

  5. October 29, 2013 at 1:55 pm

    I also have a selection of zoom lenses, from a 12-22mm wide angle, up to
    an 80-400VR. Silky stocking were out, however, during the war years because nylon was used to make parachutes and
    tents. When it comes to feeding horses, most owners are reasonably confident that what they are feeding
    their horse is right.

  1. No trackbacks yet.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: