- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- renaming a bunch of files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2003 10:04 AM
тАО08-07-2003 10:04 AM
renaming a bunch of files
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.
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2003 10:07 AM
тАО08-07-2003 10:07 AM
Re: renaming a bunch of files
Somebody's got to ask the obvious - at the risk of sounding completely stupid, I'll volunteer.
If you're just going to reply "y" anyway, why are you using the "-i" paramater?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2003 10:08 AM
тАО08-07-2003 10:08 AM
Re: renaming a bunch of files
for i in *.reg;do
oname=`echo $i|sed 's/\.orig//'`
cp -i $i $oname
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2003 10:13 AM
тАО08-07-2003 10:13 AM
Re: renaming a bunch of files
# csh
% foreach i (*.res.orig)
foreach? mv $i $i:r
foreach? end
%
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2003 10:15 AM
тАО08-07-2003 10:15 AM
Re: renaming a bunch of files
for FILE in `ls *.orig` ; do
NEW=`echo $FILE|sed s/.orig//g`
echo "rename $FILE back to $NEW?"
cp -i $FILE $NEW
done
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2003 11:21 AM
тАО08-07-2003 11:21 AM
Re: renaming a bunch of files
$ sh
$ for f in *.res.orig; do mv $f ${f%.orig}; done
$ exit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2003 12:25 PM
тАО08-07-2003 12:25 PM
Re: renaming a bunch of files
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.
- John