rename appears useless in Ubuntu
Sylphid
scott at chaos-dragon.com
Thu May 14 13:18:59 UTC 2009
On Wed, 06 May 2009 21:57:08 -0400
anthony baldwin <baldwinlinguas at gmail.com> wrote:
> Greetings,
>
> I have a little script to remove spaces from file names, and it was
> working when I was using PCLinuxOS, but not on Ubuntu.
> I used to be able to cd to a dir and do "nospace"(what I named the
> script), and it would ask me for a file extension, remove the space, and
> ask for a cookie. But on Ubuntu it does not rename the spaces.
> I can't figure for the life of me why...
>
> Here it is:
> #!/bin/bash
>
> # nospace
> # replace spaces with underscores
>
> echo "What kind of files do you wish to rename. Please enter the file
> extension:"
>
> read a
>
> for i in $(ls -1 *$a)
> do
> rename \ _ *.$a
> done
>
> ls -1 *$a
>
> echo "All done. Gimme a cookie!"
>
> exit
>
>
> I have also tried to simply do
>
> rename \ _ *.pdf (or whatever extension)
> , which, to my knowledge, without the loop, would remove the first
> space in any such file name, and have to be repeated, of course, to
> remove all spaces,
> but, it does nothing.
>
> I get no errors, but I also get no results.
> It appears to read the variable "a" for the file extension, and
> ls -1 *$a seems to list the files of that extension.
> So, the only thing that isn't productive here is rename.
>
> I've even tried to do
> rename pdf PDF *.pdf
> just to test rename, then I get an error, which I would not have seen in
> PCLOS.
> In PCLOS, this would have changed file.pdf to file.PDF without a hiccough.
> In Ubuntu I get "Bareword "pdf" not allowed while "strict subs" in use
> at (eval 1) line 1."
>
> So, apparently I'm confused about why rename seems completely useless in
> Ubuntu.
>
> Thanks.
> /tony
>
> --
> http://www.baldwinlinguas.com
> translations & interpreting
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
Try this instead
rename 's/\ /_/g' *.pdf
I'm not sure how rename functions in PCLinuxOS but ubuntu uses perlexpr, the rename man page has examples of this.
-----------
Scott Coil <scott at chaos-dragon.com>
More information about the ubuntu-users
mailing list