Renaming folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming folders
# 1  
Old 02-14-2007
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  
Old 02-14-2007
Code:
ls -l | awk ' /^d/ { print $NF } ' |
sed "s/^\([0-9]*\)\(.*\)/mv & \2\1/" | sh

# 3  
Old 02-14-2007
What about if folder name contains, spaces?
# 4  
Old 02-14-2007
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  
Old 02-14-2007
With zsh (and if zmv is available for your zsh):

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

# 6  
Old 02-14-2007
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  
Old 02-14-2007
Or more portably:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. UNIX for Dummies Questions & Answers

Archive folders and sub folders

Hi Can i archive folder and folders in with the tar command My files are located in subfolders Eg: Folder1/Folder1_1/*.pdf Folder1/Folder1_2/*.pdf Folder1/Folder1_3/*.pdf so i would like to tar all the files in Folder1_1 and Folder1_2 only not Folder1_3 that should be done next... (2 Replies)
Discussion started by: cnrj
2 Replies

3. Shell Programming and Scripting

Copy between two different folders containing same sub-folders

I have a folder like this ls input1 dir1 dir2 dir3 file1 file2 file3 dir1, dir2 and dir3 are sub-folders inside the folder input1 ls input2 dir1 dir2 dir3 file1 file2 file3 My dir1 in input1 folder has files f1, f2, f3 and f4. My dir1 in input2 folder has file f4 and f5. ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

4. Shell Programming and Scripting

Renaming folders all at a time

I have a set of folders like Jan1st, Jan2nd, Jan3rd... and so on. I need to rename them to Jan1st2010,Jan2nd2010 .... and so on at one shot. (4 Replies)
Discussion started by: realspirituals
4 Replies

5. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

6. Shell Programming and Scripting

Making 99 folders 99 folders deep

I am trying to make a unix shell script that will make 99 folders 99 deep (counting the first level folders). So far i have made it make the first 99 folders and 99 more in all of the folders. The only problem is the only way i have found is copying and pasting part of the script over and over and... (18 Replies)
Discussion started by: YukonAppleGeek
18 Replies

7. UNIX for Dummies Questions & Answers

Renaming file in Recursive folders

I have UWin version of Unix for Destop I have files with extension *.abc. I want to rename it to *.csv. Some of the filenames have spaces. I also to rename the files with extension *.abc in the corresponding subfolders ex == abc def.abc ghi jkl.abc mnopqr.abc uvwxyz.abc rename as... (4 Replies)
Discussion started by: bobbygsk
4 Replies

8. UNIX for Dummies Questions & Answers

Copying Folders without some folders... ;-)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (5 Replies)
Discussion started by: chimpu
5 Replies

9. Shell Programming and Scripting

Backing up Folders without some folders...;)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (1 Reply)
Discussion started by: chimpu
1 Replies
Login or Register to Ask a Question