Batch Renaming: Change files' extensions in many sub-directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Batch Renaming: Change files' extensions in many sub-directories
# 1  
Old 07-20-2008
Question Batch Renaming: Change files' extensions in many sub-directories

Hi all -

I'm trying to rename a large number of files all at once and need some help figuring out the command line syntax to do it. I've already done quite a bit of research with the rename and mv commands, but so far haven't found a solution that seems to work for me. So:

The files exist here:

/public_html/files

However, there are many subdirectories within /public_html/files, and the files within those subdirectories must also be renamed with the same operation. (I'm hoping to be able to rename the files in those subdirectories at the same time, since going through every single one of the sub-dirs -- there are 1000s -- would be very time consuming.)

The files that need renaming are, shall we say, .zzz files. All of them end in .zzz, but the beginnings of their file names are, of course, different.

NOTE: There are OTHER files in these directors that are NOT .zzz files (let's say .jpg files), and those files CANNOT be affected by this rename command.

Let's say I would like to rename all .zzz files within all subdirectories to .zzz_disabled (basically, to disable these files from being accessed), but keep the first part of their file names in tact.

So:

dog_ran_up_the_hill.zzz

BECOMES

dog_ran_up_the_hill.zzz_disabled

And that's pretty much it!

I think I've included all necessary info here.

Can anyone help me come up with the proper command line syntax to batch rename all the files in all the directories?

Thanks so much!
# 2  
Old 07-20-2008
Code:
find /public_html/files  -type f -name "*.zzz" | xargs -i mv '{}' '{}'_disabled

First run the find command without the xargs part to make sure you have only the files that you need, then proceed with xargs addition.

Last edited by rubin; 07-20-2008 at 01:18 AM.. Reason: then proceed with xargs addition.
# 3  
Old 07-20-2008
I tried the find command, and it didn't turn up anything Smilie
# 4  
Old 07-20-2008
Quote:
Originally Posted by dave920
I tried the find command, and it didn't turn up anything Smilie
The command works fine. You need to be more specific.
# 5  
Old 07-20-2008
This is the message I get when I enter the command:

Code:
find: /public_html/files: No such file or directory

# 6  
Old 07-20-2008
Quote:
Originally Posted by dave920
This is the message I get when I enter the command:

Code:
find: /public_html/files: No such file or directory


What is your OS ?
# 7  
Old 07-20-2008
Thanks for continuing to help me on this! Here's what uname tells me:

Linux host.XXX.com 2.6.9-42.0.10.ELsmp #1 SMP Tue Feb 27 10:11:19 EST 2007 i686 i686 i386 GNU/Linux
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in batch renaming files with bash shell script.

I have some 50+ files in the following format : abcd_vish_running_ZEBRA_20140818.dat_08-14-2014_23:08:23 abcd_vish_running_ZEB-RA_20140818.dat_08-14-2014_23:08:35 abcd_vish_running_ZEB_RA_20140818.dat_08-14-2014_23:08:37 abcd_vish_running_RI-NG_20140818.dat_08-14-2014_23:08:42... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

2. Shell Programming and Scripting

Renaming files in multiple directories

Hi I have the following file structure and I want to rename all the abc.jar files to abc_backup.jar rock@server:~/rakesh> ls -R .: test1 test2 test3 ./test1: abc.jar ./test2: abc.jar ./test3: abc.jar (2 Replies)
Discussion started by: rakeshkumar
2 Replies

3. OS X (Apple)

Batch file to move video files and retain sub-directories

I have just purchased my first ever Apple computer - and am therefore new to UNIX also. I would like to create a simple "batch file" (apologies if this is the wrong terminology) to do the following: When I plug my camera into the MAC it automatically downloads photos and videos into a new... (1 Reply)
Discussion started by: mm0mss
1 Replies

4. Shell Programming and Scripting

script for renaming a batch of files

hi i have a folder full of files. some of the names are quite off because the dimensions were the same and i had to put a 'b' after the initial number so that it didnt overwrite. what i want is a script in unix to overwrite the filwe name leaving some of the title intact, e.g. below are some... (3 Replies)
Discussion started by: shabs1985
3 Replies

5. Shell Programming and Scripting

Renaming of files with different extensions on the same path to .found with the help of loop

hi , I have certain files at the same path with differeent extensions like .dat , .txt etc ...........i need to rename them with extension .found at the same path with the help of loop.... also the files names will be like this ; abc_2010_c1.dat abc_2010_c2.dat xyz_2010_c1.txt (2 Replies)
Discussion started by: amitpta
2 Replies

6. UNIX for Dummies Questions & Answers

Batch Renaming of Files

Hello all, thanks for your time (and this forum, what an awesome resource for newbs like myself!) Anyways, I've been given the task of importing content from a directory of about...7000 HTML files. They are all named appropriately and broken down by name depending on what book they belong too.... (8 Replies)
Discussion started by: gratefulhokie
8 Replies

7. UNIX for Dummies Questions & Answers

Moving files out of multiple directories and renaming them in numerical order

Hi, I have 500 directories each with multiple data files inside them. The names are sort of random. For example, one directory has files named e_1.dat, e_5.dat, e_8.dat, etc. I need to move the files to a single directory and rename them all in numerical order, from 1.dat to 1000(or some... (1 Reply)
Discussion started by: renthead720
1 Replies

8. UNIX for Dummies Questions & Answers

Renaming files after their directory name in multiple sub directories

So I am not sure if this should go in the shell forum or in the beginners. It is my first time posting on these forums. I have a directory, main_dir lets say, with multiple sub directories (one_dir through onehundred_dir for example) and in each sub directory there is a test.txt. How would one... (2 Replies)
Discussion started by: robotsbite
2 Replies

9. Shell Programming and Scripting

Batch changing file extensions

We are moving from an OpenVMS server to a Unix server and I have a problem with ftp'ing files. When I ftp the VMS server from the Unix server, I need to "mget" some files, for example "mget test_file*.txt;". The semicolon is necessary because OpenVMS has multiple versions of the file (eg... (5 Replies)
Discussion started by: cdines
5 Replies

10. Shell Programming and Scripting

A Batch job to delete files from various directories

Hi, I have a shell script to find files older than 'X' days ($2) in directory path ($1) and delete them. Like this: my_file_remover.sh /usr/home/c 90 Now, I need to modify this script and add it in CRON, so that it checks other directories also. Like: my_file_remover.sh /usr/home/c... (3 Replies)
Discussion started by: guruparan18
3 Replies
Login or Register to Ask a Question