- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- rename 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
тАО03-12-2002 09:18 PM
тАО03-12-2002 09:18 PM
I want to rename all *.png files to *.gif under /opt
directory, how can I do?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2002 11:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2002 11:41 PM
тАО03-12-2002 11:41 PM
Re: rename files
here is one way of doing it.
First execute this command:
find /opt -name ?\*.png -exec ls {} \; > /tmp/png_files
Then inspect the file /tmp/png_files to
make sure that you really want to rename all
files in it.
Then run this command
cat /tmp/png_files | rename_script
where the rename_script looks like this
#!/bin/ksh while read filnavn
do
echo $filnavn
new=`echo $filnavn | sed s/.png$/.gif/`
echo $new
mv $filnavn $new
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-12-2002 11:55 PM
тАО03-12-2002 11:55 PM
Re: rename files
you should solve this problem with a loop construction:
mkdir /tmp/renamer
cd /opt
ls . *.png | cp /tmp/renamer
cd /tmp/renamer
for i in `ls /tmp/renamer/*
do
mv $1 `echo $i | sed s/.png/.gif/`
done
# Please check here, if the result is what you
# want. If the answer is yes, remove the files # which you no longer need
rm -f /opt/*.png
# after this, copy the files to /opt and
# delete the /tmp/renamer
cp /tmp/renamer/*.gif /opt
rm -rf /tmp/renamer
# show the effect
ls /opt/*.gif
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2002 12:14 AM
тАО03-13-2002 12:14 AM
Re: rename files
You could do that with the following script ... replace the echo by the actual command ...
#!/usr/bin/sh
for i_file in $(find /opt -name *.png)
do
o_file=$(echo $i_file | awk ' { sub(".png",".gif",$1) ; print $1 } ')
echo "mv $i_file $o_file"
done
Hope this helps,
Tom Geudens
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2002 12:19 AM
тАО03-13-2002 12:19 AM
Re: rename files
find /opt -type f -name "*.png" | while read file ; do
echo mv $file ${file%.png}.gif
done
This will preview the action. Remove the echo to actually run it.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2002 04:02 AM
тАО03-13-2002 04:02 AM
Re: rename files
mv "$oldname" "$newname"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2002 10:44 PM
тАО03-17-2002 10:44 PM