The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help renaming files bbbngowc UNIX for Dummies Questions & Answers 5 04-23-2008 03:08 PM
Renaming Files abch624 Shell Programming and Scripting 2 03-20-2008 12:54 AM
Renaming files Tygoon UNIX for Dummies Questions & Answers 7 01-06-2008 10:59 PM
renaming files systemsb UNIX for Dummies Questions & Answers 3 05-25-2006 01:56 AM
renaming files raguramtgr UNIX for Dummies Questions & Answers 4 09-21-2004 11:57 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-13-2006
mc_cool_e mc_cool_e is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 3
Help with renaming files

Anyone out there know how, in a one line UNIX Command, I could rename(mv) a file that contains variable string as part of its name. The variable string is the process instance number.

For example, I'd like to be able to rename XX_XXXXX_nnnnn.pdf (where nnnnn is a number and its value depends on the process instance number it was created in) to bkp_XX_XXXXX_nnnnn.pdf.

Thanks in advance.
  #2 (permalink)  
Old 01-13-2006
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,767
In ksh $$ = the process id. For this example I assume a procces id is the same as your process instance -
Code:
mv XX_XXXXX_$$.pdf   bkp_XX_XXXXX_$$.pdf
  #3 (permalink)  
Old 01-13-2006
mc_cool_e mc_cool_e is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 3
Thanks Jim, unfortunately I wish to rename the prior instance of the file, so don't know the process id other than its part of the file.

Is there any way to pipe the output from the ls command into mv?
  #4 (permalink)  
Old 01-13-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,124
In ksh:

ls *.pdf | while read f ; do echo mv $f bkp_$f ; done

Run it as above and let it echo the commands it would do. If it looks good, rerun the above command but remove the "echo". This will actually do the move.
  #5 (permalink)  
Old 01-13-2006
mc_cool_e mc_cool_e is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 3
Perderabo,

that is awesome. Thanks very much for your help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0