|rename not working in Ubuntu?
||[May. 6th, 2009|09:54 pm]
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:
# replace spaces with underscores
echo "What kind of files do you wish to rename. Please enter the file extension:"
for i in $(ls -1 *$a)
rename \ _ *.$a
ls -1 *$a
echo "All done. Gimme a cookie!"
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.
Did some googling....
I found that a much simple rename script does the job in Ubuntu, and removes spaces from all files in a dir without specifying the extension.
rename 's/ /_/g' *
Sort of simpler...
The thing is, rename clearly works differently in Ubuntu than PCLOS, and I'd like to know how to do simple extension renames, now,
such as rename all .JPG and .jpeg files to .jpg files.
In PCLOS it would have been:
rename JPG jpg *.JPG
rename jpeg jpg *.jpeg
pretty simple...but those don't work with ubuntu's rename, which is apparently a bit of perly magic, and in order for me to learn to make good use of it, I would have to learn a bit something of perl expressions.
I don't know diddely about perl.
PCLOS rename utility was much simpler to use, in many respects, as such.