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 11:08 AM
Renaming Files abch624 Shell Programming and Scripting 2 03-19-2008 08:54 PM
renaming files jxh461 UNIX for Dummies Questions & Answers 1 02-04-2008 05:32 PM
renaming files systemsb UNIX for Dummies Questions & Answers 3 05-24-2006 09:56 PM
renaming files raguramtgr UNIX for Dummies Questions & Answers 4 09-21-2004 07:57 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-20-2007
Registered User
 

Join Date: Dec 2007
Posts: 3
Renaming files

Hello!
I am not familiar with UNIX and I have this problem:

I need to move files from a UNIX machine to a PC. UNIX file names contain ":" as special character which is not recognized in a PC.
How can I change ":" for "_" in the name of a bunch of files in UNIX?

Thanks for your help.

Last edited by Tygoon; 12-20-2007 at 05:30 PM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-20-2007
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 643
Code:
for file in *
do
  mv $file `echo $file | sed 's/\:/_/g'`
done
Reply With Quote
  #3 (permalink)  
Old 12-20-2007
Registered User
 

Join Date: Dec 2007
Posts: 3
Thank you for your help!
Reply With Quote
  #4 (permalink)  
Old 12-21-2007
Registered User
 

Join Date: Dec 2007
Posts: 3
How to includes files and folder inside a folder

Hi!
I tried the procedure described and I could change the file names inside the main folder. I would like this process to include any subfolders and files included in the main folder (and not repeating it in each folder!).
Thanks!
Reply With Quote
  #5 (permalink)  
Old 12-25-2007
Registered User
 

Join Date: Dec 2007
Location: Istanbul
Posts: 23
Quote:
Originally Posted by Tygoon View Post
Hi!
I tried the procedure described and I could change the file names inside the main folder. I would like this process to include any subfolders and files included in the main folder (and not repeating it in each folder!).
Thanks!
extending previous solution for subfolders:

for file in `find .`
do
mv $file `echo $file | sed 's/:/_/g'`
done
Reply With Quote
  #6 (permalink)  
Old 01-06-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 643
Quote:
Originally Posted by mehmet_demirez View Post
extending previous solution for subfolders:

for file in `find .`
do
mv $file `echo $file | sed 's/:/_/g'`
done
I'd suggest adding a '-type f' to the find command to to avoid it matching directories too?
Reply With Quote
  #7 (permalink)  
Old 01-06-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,423
Quote:
Originally Posted by Smiling Dragon View Post
I'd suggest adding a '-type f' to the find command to to avoid it matching directories too?
i would suggest using while loop instead. ( although it should be ok with a for loop if files with spaces are properly parsed)
Code:
# find . -type f | while read line;  do .... ; done
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0