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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.