Renaming files in multiple directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming files in multiple directories
# 1  
Old 10-15-2013
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

Code:
rock@server:~/rakesh> ls -R
.:
test1  test2  test3

./test1:
abc.jar

./test2:
abc.jar

./test3:
abc.jar


can anyone help with suggestion ?
# 2  
Old 10-15-2013
Code:
ls -R
.:
test1  test2  test3

./test1:
abc.jar

./test2:
abc.jar

./test3:
abc.jar

for f in $(find . -name 'abc.jar' -type f);do mv -vv $f ${f/.jar/_backup.jar};done
'./test1/abc.jar' -> './test1/abc_backup.jar'
'./test3/abc.jar' -> './test3/abc_backup.jar'
'./test2/abc.jar' -> './test2/abc_backup.jar'

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 10-15-2013
Quote:
Originally Posted by in2nix4life
Code:
for f in $(find . -name 'abc.jar' -type f);do mv -vv $f ${f/.jar/_backup.jar};done

The for-loop is unnecessary. Just use find's -exec.

Regards,
Alister
This User Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. Shell Programming and Scripting

Renaming multiple files

I have 34 file in a directory that all have different names, however, they do have 1 pattern in commmon. They all have "-10-11-2010" date format in the name. I want to replace the date in the file name with a supplied date or maybe even the system date. I am sure I will be using awk or sed to... (9 Replies)
Discussion started by: Harleyrci
9 Replies

3. Shell Programming and Scripting

renaming multiple files

I have to rename 100+ files at a time on the server & was trying to use a script for doing that. I have used ultra edit to create a file having current filename & new file name as below file234.txt | file956.txt file687.txt | file385.txt There is no fixed pattern while renaming & would... (20 Replies)
Discussion started by: crux123
20 Replies

4. 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

5. 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

6. Shell Programming and Scripting

Renaming multiple files

Hi, I have several hundred files I need to rename, and I'm would rather not hit F2 for each file individually to rename them. Example of file: large1961.jpg What I need the file to be renamed as: 1961.jpg I don't know what type of command I can execute within a shell script that would... (7 Replies)
Discussion started by: jayell
7 Replies

7. Shell Programming and Scripting

Renaming multiple files

I have a bunch of files txt1.csv--2008 thru to txt3.csv--2008. If i wanted to rename these files all at the same time to txt*.csv-2008 what would be the best way to do it... Just need to get rid of the extra - in each file name.. not all files are going to be called txt*.csv--2008. Just... (6 Replies)
Discussion started by: Jazmania
6 Replies

8. UNIX for Dummies Questions & Answers

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... (10 Replies)
Discussion started by: dave920
10 Replies

9. UNIX for Dummies Questions & Answers

Renaming multiple files

Help! I was trying to rename multiple files. Like in DOS, i decided to use wildcards and now i am missing some files. Any ideas on how to recover them? Or find out where the files went? I had these 3 files resume1.log elecresume.log compresume.log The command I ran was mv *.log *.log.bak... (6 Replies)
Discussion started by: rmayur
6 Replies

10. Shell Programming and Scripting

Renaming multiple files

Can someone please tell me how I can rename a bunch of files at a time. I hava a directory that has 700+ files that are named *.xyz and I would like to rename them to *.abc . How can I do that with a simple command ? mv *.xyz *.abc did not work. Thanks in advance (4 Replies)
Discussion started by: jxh461
4 Replies
Login or Register to Ask a Question