The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Renaming files cedrichiu Shell Programming and Scripting 3 04-06-2007 01:35 AM
Renaming files whatsup Shell Programming and Scripting 8 07-10-2006 02:47 PM
Copying Folders without some folders... ;-) chimpu UNIX for Dummies Questions & Answers 5 04-26-2004 09:25 AM
Backing up Folders without some folders...;) chimpu Shell Programming and Scripting 1 04-26-2004 07:02 AM
Renaming a file name dbrundrett Shell Programming and Scripting 2 01-06-2004 06:36 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-14-2007
Registered User
 

Join Date: Feb 2007
Posts: 10
Stumble this Post!
Renaming folders

Hello,

I'm new to unix and I have to rename all folder fron the current folder from a name like "xx - Name of the Folder" to "Name of the Folder - xx".

xx is a number ...

Can somebody, please, help?

Thank you!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-14-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
Code:
ls -l | awk ' /^d/ { print $NF } ' |
sed "s/^\([0-9]*\)\(.*\)/mv & \2\1/" | sh
Reply With Quote
  #3 (permalink)  
Old 02-14-2007
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 518
Stumble this Post!
What about if folder name contains, spaces?
Reply With Quote
  #4 (permalink)  
Old 02-14-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
Quote:
Originally Posted by tayyabq8
What about if folder name contains, spaces?
Code:
find . -type d -print | sed -e "s;\./\([^/]*\).*;\1;" -e "s/^\([0-9]*\)\(.*\)/mv \"&\" \"\2\1\"/" | sh

Last edited by anbu23; 02-14-2007 at 04:52 AM.
Reply With Quote
  #5 (permalink)  
Old 02-14-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,516
Stumble this Post!
With zsh (and if zmv is available for your zsh):

Code:
autoload zmv
zmv '(*) - (*)' '$2 - $1'
Reply With Quote
  #6 (permalink)  
Old 02-14-2007
Registered User
 

Join Date: Feb 2007
Posts: 10
Stumble this Post!
anbu23,

Thak's but the line seems to be a little wrong: "mv: cannot access 2005 - Broken Flowers" ..

Don't know why... I'm root on this session...
Reply With Quote
  #7 (permalink)  
Old 02-14-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,516
Stumble this Post!
Or more portably:

Code:
for i in [0-9]*;do # adjust the globbing for your needs
  mv "$i" "${i#*- } - ${i% -*}"
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:40 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