- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Rename file
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
Forums
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
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
тАО06-11-2004 02:47 AM
тАО06-11-2004 02:47 AM
I need to rename 10000 files all in 1 shot,
I know "mv command" doesn't support wild card characters
For eg: Files
payee1.dat to payee_plan1.dat
payee2.dat to payee_plan2.dat
payee3.dat to payee_plan3.dat
.....
Solved! Go to Solution.
- Tags:
- mv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 02:54 AM
тАО06-11-2004 02:54 AM
Re: Rename file
filenames=`ls -1 | grep payee`
for filenames in $filenames
do
mv $filenames $filenames.old
done
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 02:55 AM
тАО06-11-2004 02:55 AM
Re: Rename file
Using cut...
for name in `ls *.php3`
do
name1=` echo $name| cut -f 1 -d . `
mv $name1.php3 $name1.php
done
Cut the first part and last part...
- Tags:
- cut
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 02:58 AM
тАО06-11-2004 02:58 AM
Re: Rename file
do
name1='echo name|cut 1-5`
name2='echo name|cut 6-10`
mv $name $name1_plan$name2
done
Or make a file and use:
for name in `cat file.in`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 02:59 AM
тАО06-11-2004 02:59 AM
Re: Rename file
while read file
do
file=${file%.dat}
file=${file#payee}
mv payee${file}.dat payee_plan${file}.dat
done
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 03:08 AM
тАО06-11-2004 03:08 AM
Re: Rename file
SUFIX=payee_plan
FILES=`ls`
for FILE in $FILES
do
DOT_POSSITION=`echo $FILE|awk '{ print index( $1, ".")}'`
POSSITION=`expr $DOT_POSSITION - 1`
SUFIX=`echo $FILE|cut -c$POSSITION-`
NEW_NAME=${PREFIX}${SUFIX}
mv $FILE $NEW_NAME
done
Rgds.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 03:27 AM
тАО06-11-2004 03:27 AM
Re: Rename file
I used this simple (I'm sure I can figure out a shorter 'smarter' solution :-) perl one-liner to do my job. (tested):
ls .*560* | perl -ne 'chop; $o=$_; $_ =~ s/560/585/; rename $o,$_;'
For you that could be (untested):
ls payee*.dat | perl -ne 'chop; $o=$_; $_ =~ s/payee/payee_plan/; rename $o,$_;'
Now, before acting on the files I always make a dry-run with print or echo statements.
So try this first:
ls payee*.dat | perl -ne 'chop; $o=$_; $_ =~ s/payee/payee_plan/; print "rename $o,$_\n";'
hth,
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 03:30 AM
тАО06-11-2004 03:30 AM
Re: Rename file
{s/\.\/([a-zA-Z]{1,})([0-9]{1,})\.dat/\/usr\/bin\/mv \1\2.dat \1_plan\2.dat/;print $_;system $_;};'
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 04:38 AM
тАО06-11-2004 04:38 AM
SolutionStart vi without a filename. Read in the list of filenames, one filename per line. Make each line into an mv command. Write the commands to the shell for execution.
example, read in all files in current directory one filename per line. Add a space at the end of each filename. Change each filename to a move command while duplicating the filename. Change the space at the end of each second filename to .new. Write the script to the shell for execution. Exit vi without bothering to save the script.
$vi
$:r !ls -1
:g;$;s;$; ;
:g;.*;s;.*;mv -i &&;g
:g; $;s; $;.new
:w !sh
:q!
Of course many similar operations are possible, limited only by your skill with vi.
- Tags:
- vi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 04:45 AM
тАО06-11-2004 04:45 AM
Re: Rename file
create a sample directory somewhere with several sample files in it and try it out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2004 06:30 AM
тАО06-11-2004 06:30 AM
Re: Rename file
ls payee*.dat |
sed 's/\(payee\)\(.*.dat\)/\1\2\
\1_plan\2/' |
xargs -i -t -n2 mv
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2004 09:46 PM
тАО06-18-2004 09:46 PM
Re: Rename file
We can do it with a simple script.
ext=".dat"
name="payee"
new="payee_plan"
i=1
while [[ $i -lt 10001 ]]; do
mv $name$i$ext $new$i$ext
let i=i+1
done
Regards,
Muthukumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2017 10:51 PM - edited тАО10-21-2017 12:30 PM
тАО10-09-2017 10:51 PM - edited тАО10-21-2017 12:30 PM
Re: Rename file
There are many ways to do this but I always use very simple software and works with all platform. For checking this software go to google and type- BatchRenameFiles Tool. Check the first result.