HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: rename script.
Operating System - HP-UX
1837097
Members
2248
Online
110112
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
12-01-2004 11:37 AM
12-01-2004 11:37 AM
rename script.
Hi,
it's help call rather than a question, I trying to write a script that will rename all files in given /mydir/ into inremented by +1 numeric name. Like
file012.dat 101.dat
file333.dat 102.dat
file4.xls 103.xls
I'm on HPUX, thoug probably I will need to run this on PC (after installing Perl) or just under DOS??
Thanks all
Dai
it's help call rather than a question, I trying to write a script that will rename all files in given /mydir/ into inremented by +1 numeric name. Like
file012.dat 101.dat
file333.dat 102.dat
file4.xls 103.xls
I'm on HPUX, thoug probably I will need to run this on PC (after installing Perl) or just under DOS??
Thanks all
Dai
beer or not beer
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2004 02:59 AM
12-02-2004 02:59 AM
Re: rename script.
Here is a ksh script that should work. It goes through all the files in a directory and creates a "mv" statement to rename.
I prefer a script that creates another script so that it gives me a chance to review the "mv" commands.
I also recommend moving the files to another directory. If you move into the same directory you have the potential of renaming a file to a name that already exists.
#!/usr/bin/ksh
typeset -Z3 cnt=0
cd /your/path
ls -1 >/tmp/files
while read line ; do
let "cnt = cnt + 1"
echo "mv '$line' '../newloc/${cnt}.${line##*.}'"
done /tmp/moveit
File /tmp/moveit will be a list of "mv" commands. Enter "sh /tmp/moveit" to run.
HTH
-- Rod Hills
I prefer a script that creates another script so that it gives me a chance to review the "mv" commands.
I also recommend moving the files to another directory. If you move into the same directory you have the potential of renaming a file to a name that already exists.
#!/usr/bin/ksh
typeset -Z3 cnt=0
cd /your/path
ls -1 >/tmp/files
while read line ; do
let "cnt = cnt + 1"
echo "mv '$line' '../newloc/${cnt}.${line##*.}'"
done /tmp/moveit
File /tmp/moveit will be a list of "mv" commands. Enter "sh /tmp/moveit" to run.
HTH
-- Rod Hills
There be dragons...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2004 02:59 AM
12-02-2004 02:59 AM
Re: rename script.
Hi,
cd /mydir
NUMBER=100
for file_name in `ls`
do
endname=`echo $file_name|cut -d'.' -f2`
mv $file_name "$NUMBER.$endname"
NUMBER=`expr $NUMBER + 1`
done
Be sure what no directory is present in /mydir else you must to add test if file_name is a directory or not before rename it
Rgds
JMB
cd /mydir
NUMBER=100
for file_name in `ls`
do
endname=`echo $file_name|cut -d'.' -f2`
mv $file_name "$NUMBER.$endname"
NUMBER=`expr $NUMBER + 1`
done
Be sure what no directory is present in /mydir else you must to add test if file_name is a directory or not before rename it
Rgds
JMB
Si vous ne faites jamais de bétises, c'est que vous ne faites rien de difficile. Et ça c'est une grosse bétise.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP