rename appears useless in Ubuntu
Rashkae
ubuntu at tigershaunt.com
Wed May 13 03:00:37 UTC 2009
anthony baldwin 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
>
If you had tried man rename, it would have given you a pretty big clue.
Now that the mandatory snark is out of the way.
for reasons that are way beyond my mortal understanding, the maintainers
of Debian (and by extension, Ubuntu) in their infinite wisdom, have
decided to replace the standard rename program that's part of util-linux
package in every distro, with a perl scrip normally called prename, even
though the command syntax for prename is completely different. (The
standard rename is installed as "rename.ul")
If that were not enough, to add insult to injury, rename is actually a
symlink that is meant to be part of the debian alternatives so you can
choose which program it links too, but at least back in the Gutsy days,
rename.ul wasn't configured as an option for rename.
So run update-alternatives --config rename, and see if rename.ul is
available as an option. If it's not, then run this command to make it
so: (should all be one line)
update-alternatives --install /usr/bin/rename rename /usr/bin/rename.ul
50 --slave /usr/share/man/man1/rename.1.gz rename.1.gz
/usr/share/man/man1/rename.ul.1.gz
And feel free to file a bug on launchpad if that long command is still
necessary.
More information about the ubuntu-users
mailing list