[SOLVED] Convert all file extensions in one directory to another file extension
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
mv: cannot `windows-system-characteristics-schema.xsd' change to `windows-system-characteristics-schema.oval': Permission denied
mv: cannot `xmldsig-core-schema.xsd' change to `xmldsig-core-schema.oval': Permission denied
but after sudoing got this then:
user@user:/usr/local/share/ovaldi/xmltest$ sudo for i in *.xsd; do mv "$i" "${i/.xsd/.oval}"; done
bash: Syntax error beside "do" cannot continue with it.
What is the issue with 'do'?
do is the opening of the for loop. What I wrote is actually a 4 line script rolled into one line using semicolons, ie:
Code:
for i in *.xsd
do
mv "$i" "${i/.xsd/.oval}"
done
Chances are the sudo is what's messing things up, since it's "sudoing" the for, and not the rest. I never use sudo, so I can't really test it, but this might be the change you need:
Code:
for i in *.xsd; do sudo mv "$i" "${i/.xsd/.oval}"; done
Yes it will, the quotes cover that. I use it all the time.
No it won't. Do an example yourself and see.
Code:
touch old\ file.old
touch old-file.old
for i in *.old; do mv "$i" "${i/.old/.new}"; done
You will get "old not found" and "file.old not found" errors when you run that for loop. Unless you've changed your field separator in the IFS variable to see newlines as the field separator that for loop does not work on file names with spaces. The for loop separates arguments based on spaces. That's why I gave you the while read line loop.
touch old\ file.old
touch old-file.old
for i in *.old; do mv "$i" "${i/.old/.new}"; done
You will get "old not found" and "file.old not found" errors when you run that for loop. Unless you've changed your field separator in the IFS variable to see newlines as the field separator that for loop does not work on file names with spaces. The for loop separates arguments based on spaces. That's why I gave you the while read line loop.
RHEL:
Code:
[eggroll@picard test]$ touch old\ file.old
[eggroll@picard test]$ touch old-file.old
[eggroll@picard test]$ for i in *.old; do mv "$i" "${i/.old/.new}"; done
[eggroll@picard test]$ ls
old file.new old-file.new
I have also tested it successfully on CentOS, Fedora, Mint, OpenSUSE, Cygwin, and BusyBox. None of them have modified IFS. I just set up the Mint box not 24 hours ago, haven't modified anything on it really, and it works fine. If I had access to more distros, I would try them as well, but so far I haven't found a single distro that it doesn't work on, including the limited ones used on embedded systems like the GESBC-9260S and Gumstix.
You would be right if I had written it like:
Code:
for i in $(ls *.old); do mv "$i" "${i/.old/.new}"; done
but that's why I didn't write it like that. "for i in *.old" does not work the same way as "for i in $(ls *.old)", and does not suffer from the problem you're describing, at least not on any system I've ever used.
Last edited by suicidaleggroll; 03-02-2012 at 10:27 AM.
for i in $(ls *.old); do mv "$i" "${i/.old/.new}"; done
but that's why I didn't write it like that. "for i in *.old" does not work the same way as "for i in $(ls *.old)", and does not suffer from the problem you're describing, at least not on any system I've ever used.
Ah I had it confused with the ls command as I've tried that in the past. My bad.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.