I want to rename a bunch of files. The filenames are of the form *.res.orig and I want to rename them all back to *.res
I found an example in the book UNIX Power Tools, and modified it slightly.
This works: # ls -d *.orig | sed "s/\(.*\ \.orig$/cp '&' '\1'/" | sh -v
But if I try it with cp -i in order to get a prompt whether to overwrite an existing file, it fails. It prompts me, but then doesn't accept my answer, "yes", and go ahead and copy the file, and continue with the next file. Like so: # ls -d *.orig | sed "s/\(.*\)\.orig$/cp -i '&' '\1'/" | sh -v cp -i 'dev1_dev_fat.res.orig' 'dev1_dev_fat.res' overwrite dev1_dev_fat.res? (y/n) # y sh: y: not found. #
I used -i the first time I tried it because I didn't know if I had botched typing in the command correctly and whether it was going to do what I wanted. Of course, after I saw that it was going to do what I wanted, I was then confident doing without the -i, and I successfully renamed all the files.
The intent of my post to the forum was really to learn why the command was failing, for education purposes and professional/technical growth. It seems a nice solution to a somewhat common situation which I could remember how to do from the command line without having to have a script stored somewhere.