[arch-general] renaming files

Vitor Eiji Justus Sakaguti vitoreiji0 at gmail.com
Thu Mar 1 18:48:23 EST 2012


On Thu, Mar 1, 2012 at 8:13 PM, pete <p.nikolic1 at btinternet.com> wrote:
> I have some 350 picture files  with names  along the lines of
> "IMG_7127 EOS-1D Mark III copy.jpg"    i would like to rename them all
> to more like "IMG_7127.jpg"  i have tried a few times tonight and cant
> get my head around it anyone got a script that can do it

I like using vim for those tasks because of the interactivity (I fear
my dirty little scripts will go rogue and ruin all my files...)
Here's how it works:
$ ls | vim -
Then I get in vim one line per filename (unless there's a file with a
\n in its name, wich there never will be on my system!)
I use some vim commands to get something like (usualy something with
:%s/foo/bar)
...
mv "IMG_7127 EOS-1D Mark III copy.jpg" "IMG_7127.jpg"
mv "IMG_7128 EOS-1D Mark III copy.jpg" "IMG_7128.jpg"
...
Then I triple check if everything is OK (did I mention I'm paranoid?)
And finaly
:w !sh
To make vim execute the whole file as a sh script.
Done.


More information about the arch-general mailing list