Thomas Thurman on 9 Sep 2005 13:55:31 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] batch renaming


Art Alexion said:
> in dos if I wanted to rename a batch of files i a directory, I could do
>
>     move (or rn) ??.txt 61??.txt
>
> and it would rename all of the two character-named text files to prepend
> 61.  Bash won't let me do this as
>
>     mv ??.txt 61??.txt

The reason this doesn't work is the way wildcards are expanded in the
shell. Suppose you have aa.txt, bb.txt and cc.txt in the current
directory. Then in

  mv ??.txt 61??.txt

the "??.txt" gets expanded to the names of all the files it matches, i.e.
"aa.txt bb.txt cc.txt", but the "61??.txt" doesn't match any files in the
current directory, so it ends up as an empty string. So what mv finally
sees is:

  mv aa.txt bb.txt cc.txt

hence your error about "target must be a directory".

> Is there a command that will let me do this?

It's not in all installations, but you might find that you have Larry
Wall's "rename" command available. It takes a regular expression and a set
of filenames. So in your case you'd write

  rename 's/^/61/' ??.txt

Thomas

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug