Renaming folders all at a time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming folders all at a time
# 1  
Old 08-09-2011
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.
# 2  
Old 08-09-2011
Try this:
Code:
find /path/to/your/dirs/ -type d -name "Jan*" | xargs rename -n 's/$/2010/'

It will not do anything, just tell you what it would do. Then, if you like what you see, just take out the -n switch, and it will do the renaming. Like this:
Code:
find /path/to/your/dirs/ -type d -name "Jan*" | xargs rename 's/$/2010/'

Note that you will have to do the 'rename' utility, that uses perl regex's. If you type 'rename' and see something like this:
Code:
$ rename
Usage: rename [-v] [-n] [-f] perlexpr [filenames]

You are good to go. Otherwise try to invoke 'prename' instead of rename.
# 3  
Old 08-10-2011
Error

But rename will not work with folders I guessSmilie
# 4  
Old 08-11-2011
Code:
$ ls -1d Jan* | awk ' { print "mv "$0" "$0"2010" } ' | sh

This User Gave Thanks to jayan_jay For This Post:
# 5  
Old 08-11-2011
Quote:
Originally Posted by realspirituals
But rename will not work with folders I guessSmilie
It does on my linux box. What system are you on?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Renaming hundreds of files at the same time

Hi, I am having issues trying to figure out how to rename files like this: TEST1_B.tt To SQP_CAN_B.tt I have hundreds of files like those, I need to rename them automatically. Any help will be greatly appreciated. Thanks, (5 Replies)
Discussion started by: ocramas
5 Replies

2. Shell Programming and Scripting

Shell Script to delete files within a particular time frame under multiple sub folders

Greetings! I'm looking for starting information for a shell script. Here's my scenario: I have multiple folders(100) for example: /www/test/applications/app1/logs /www/test/applications/app2/logs Within these folders there are log files files that need to be deleted after a month. ... (3 Replies)
Discussion started by: whysolucky
3 Replies

3. Shell Programming and Scripting

Removal of files/folders created during a period of time

Hi, I have some folders (containing files) which gets created daily and names start with 'TT_' . I would like to remove these folders every month end. Could you please provide me the commands and also the syntax to schedule through crontab. Thanks, Archana (3 Replies)
Discussion started by: archana.n
3 Replies

4. Shell Programming and Scripting

To find the time stamps history of the files within the sub-folders

Hi - Can anyone help me to get the shell script for the below scenario I need to find out the time stamps history for the files residing within the subfolders. Ex.. Let say I got directory structure like /home/project1/ -- Fixed directory Now within the project there are many... (1 Reply)
Discussion started by: pankaj80
1 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. 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

7. Shell Programming and Scripting

Finding files older than the current date and time and renaming and moving

Hi, I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Discussion started by: ragavhere
7 Replies

8. Shell Programming and Scripting

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! (6 Replies)
Discussion started by: mirciulicai
6 Replies

9. UNIX for Dummies Questions & Answers

Renaming files to have date/time in filename

I have a program that will export my data to a single file, but it assigns a file name that is overridden every time I run the program. I need to change the file name to have a sequential number in the filename. How do I rename a file so that the filename contains the system date and time. I want... (5 Replies)
Discussion started by: wayneb
5 Replies
Login or Register to Ask a Question