Rename multiple files at once
Stephen Ryan
taketwoaspirin at gmail.com
Fri Dec 2 19:48:44 UTC 2005
On 12/2/05, Stephen Ryan <taketwoaspirin at gmail.com> wrote:
>
>
>
> On 12/2/05, Wade Smart <wade at wadesmart.com> wrote:
> >
> > 12022005 1312 GMT-5
> >
> > I have a odd situation where I have to rename 130 picture files from a
> > random number to 1.jpg, 2.jpg, etc. Is there anyway to automate that?
> > Quickly!
> >
> > Wade
>
>
> Yes, there is. If the files are all currently in the same directory, and
> are all named something_or_other.jpg, the following will rename them to
> 1.jpg, 2.jpg, in a random-ish order:
>
> $ for i in *.jpg ; do mv $i $((++c)).jpg ; done
> $ unset c
> $ unset i
>
> The "for i in FOO ; do BAR ; done" part runs a particular command once for
> each file specified by FOO. The precise command is specified by BAR, and it
> renames (mv) that file to a number followed by ".jpg"; it also adds one to
> the number so that each file gets a different number.
>
> "unset c" and "unset i" just clear the values of those two shell
> variables; if you close the terminal window afterwards, you won't need to
> run those two commands.
>
> Holler if you need more help, or if I misunderstood your problem.
>
One other thing: if your files aren't completely randomly-named and there's
a piece of the filename that you need to keep, (i.e., you want to rename
DSCF00012.jpg to 12.jpg) check out mmv (it's in universe).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20051202/cef5c810/attachment.html>
More information about the ubuntu-users
mailing list