renaming a bunch of files using for and mv
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. |
Code:
for i in $(ls *.doc) |
But you'll be in trouble any of the files has a space in its name. Better to use
Code:
for i in *.doc |
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!! :) |
Quote:
Evo2. |
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 |
Quote:
Quote:
"a bunch of errors" [ "No cheese in fridge. HALT" ;) ] is not helpful, at all, to anyone. Please help us help yourself. |
All times are GMT -5. The time now is 02:05 PM. |