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.
hello, this is a rather dumb question I suppose, but here goes anyway.
Basically I need to rename a bunch of .doc files using the for-structure and the mv command (w/ wildcards) in bash. I guess this would be a bit easier if I'd use the rename command, but since this is a school assignment of sorts I need to use for & mv.
The .doc files are named "1filename.doc", "2filename.doc" etc.
And I've got to rename them to "aaa_1filename.doc", "aaa_2filename.doc", "aaa_3filename.doc" and so on.
Tried to dabble quite a bit with the for and mv commands, basically just got a bunch of errors. Every damn time. For 2 hours. The most common error was "mv: missing destination file operand after ..."
So, what would be the right way to do this using for and mv? Thanks in advance, and I apologize if this is in the wrong section or just completely useless in other possible ways.
I did think that when I posted it but I'd already edited twice to correct syntax errors so didn't again lol as the OP gave some example filenames.
Who puts spaces in filenames anyway?!?!? tut tut!!
lol. Just realised actually that my example wouldn't work with spaces because ls when used in a for loop tokenizes on spaces. When I renamed about 40K files to remove the space a while back I used something like:
Code:
find -depth ~/mydir/ | while read i
do
mv "$i" $(echo "$i" | sed "s/ /_/g")
done
The advantage here is that the depth first search renames the files in a directory before the directory itself (ie, so you don't rename the directory and then the old location becomes invalid! ). Was surprisingly quick to run to be honest!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.