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 and shell scripting languages 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 05:35 AM
Renaming files whatsup Shell Programming and Scripting 8 07-10-2006 06:47 PM
Copying Folders without some folders... ;-) chimpu UNIX for Dummies Questions & Answers 5 04-26-2004 01:25 PM
Backing up Folders without some folders...;) chimpu Shell Programming and Scripting 1 04-26-2004 11:02 AM
Renaming a file name dbrundrett Shell Programming and Scripting 2 01-06-2004 10:36 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 02-14-2007
mirciulicai mirciulicai is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 10
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!
  #2 (permalink)  
Old 02-14-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
ls -l | awk ' /^d/ { print $NF } ' |
sed "s/^\([0-9]*\)\(.*\)/mv & \2\1/" | sh

  #3 (permalink)  
Old 02-14-2007
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 579
What about if folder name contains, spaces?
  #4 (permalink)  
Old 02-14-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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 08:52 AM..
  #5 (permalink)  
Old 02-14-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
With zsh (and if zmv is available for your zsh):


Code:
autoload zmv
zmv '(*) - (*)' '$2 - $1'

  #6 (permalink)  
Old 02-14-2007
mirciulicai mirciulicai is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 10
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...
  #7 (permalink)  
Old 02-14-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
Or more portably:


Code:
for i in [0-9]*;do # adjust the globbing for your needs
  mv "$i" "${i#*- } - ${i% -*}"
done

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:52 AM.


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