Visit Our UNIX and Linux User Community


Having trouble with find rename jpg command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Having trouble with find rename jpg command
# 1  
Old 12-18-2013
Having trouble with find rename jpg command

Hi,

I have a large series of directories and subdirectories with many jpgs in them. I need to do two things:

1. Create a copy of each jpg found within it's own subdirectory
2. Rename this copied jpg such that apple.jpg becomes apple_m.jpg

I have tried to run the following commands in order:


//this creates a copy of every jpg found and appends '_m' to the end of it
Code:
find . -name '*.jpg' -execdir cp {} {}_m \;

//now again find everything with 'jpg_m' at the end and rename it as filename_m.jpg
Code:
find . -name '*.jpg_m' -execdir rename -v 's/\.jpg_m/_m\.jpg/' {} \;

However the 2nd command does'nt seem to work, can someone please explain what I'm doing wrong?

Thanks,
Adi
# 2  
Old 12-18-2013
Hello,

Could you please try the following code.

Code:
a=`find . -name "*.jpg"`
set -A array $a
 
for i in ${array[@]}
do
file_name=`basename $i`
echo $file_name
new_name=`echo $file_name"_m"`
cp "$file_name" "$new_name"
done


Hope this may help you.

NOTE: kindly use cp -p to copy the files in same permissions.


Thanks,
R. Singh

Last edited by RavinderSingh13; 12-18-2013 at 05:35 AM.. Reason: mentioning the use for cp -p command

Previous Thread | Next Thread
Test Your Knowledge in Computers #708
Difficulty: Medium
The MySQL SELECT statement allows you to read data from only a single table.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux find jpg and sort by date

I want to find all jpg files and then sort them by modification date. This is where I started. find . -type f -name "*.jpg" I tried to pipe a sort in there but that did not seem to work. Do I need to use xargs? (10 Replies)
Discussion started by: cokedude
10 Replies

2. Shell Programming and Scripting

Trying to find and rename files

but it's not working. Hello all. I'm running the following command to find files with a specific name and rename them, but the command prompt returns a short 10 seconds after executing and doesn't find or rename anything. What am I doing wrong here? find . -type f | for file in... (3 Replies)
Discussion started by: bbbngowc
3 Replies

3. Shell Programming and Scripting

Find directories with same name and rename them

Hello Im trying to make a script in bash shell programming to find subdirectories with the same name into the same directory and rename one of them!! Could you please help me? Thanks in advance (1 Reply)
Discussion started by: BTKBaaMMM
1 Replies

4. Shell Programming and Scripting

find and copy script trouble

Hi guys First thing to say is that I am entirely new to Shell Scripting and am trying to write a script to do something I thought would be relatively simple, but has escaped me. Essentially, I want to take file name information from a list, find the files listed and then copy the results into... (0 Replies)
Discussion started by: acheron
0 Replies

5. Shell Programming and Scripting

Find and Rename files using (find mv and sed)

In response to a closed thread for degraff63 at https://www.unix.com/shell-programming-scripting/108882-using-mv-find-exec.html the following command might do it as some shells spit it without the "exec bash -c " part: Find . -name "*.model" -exec bash -c "mv {} \`echo {} | sed -e 's//_/g'\`"... (0 Replies)
Discussion started by: rupert160
0 Replies

6. Shell Programming and Scripting

Rename all ".JPG" files to ".jpg" under all subfolders...

Hi, Dear all: One question ! ^_^ I'm using bash under Ubuntu 9.10. My question is not to rename all ".JPG" files to ".jpg" in a single folder, but to rename all ".JPG" files to ".jpg" in all subfolders. To rename all ".JPG" to ".jpg" in a single folder, for x in *.JPG; do mv "$x"... (7 Replies)
Discussion started by: jiapei100
7 Replies

7. Shell Programming and Scripting

find jpg's mkdir script help

I am having a problem getting this to work right. The script needs to search through directories and subdirectories. If a jpg is found then create a folder in that directory, so on and so forth. Here is what I have so far but it doesn't work right. Help please #!/bin/bash for d in `find ./... (1 Reply)
Discussion started by: jedhypes
1 Replies

8. Shell Programming and Scripting

Simple BASH shell script to rename webcam jpg and copy into a new directory.

System: Ubuntu Intrepid Ibex I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files. So, take the following file: /home/slag/www/webcam.jpg Rename it--preferably with a time stamp. Place it in say: /home/slag/www/history/ ... (4 Replies)
Discussion started by: robfindlay
4 Replies

9. Shell Programming and Scripting

Find and rename

Hi, I was wondering if there is a way to find a particular file and then give it as an input to a program and then dump it into another file. Something like this: find ./ -name '*.txt' -exec ~/processText {} > mod.<current_file> \; I've been trying all sorts of weird things but not... (2 Replies)
Discussion started by: Legend986
2 Replies

10. UNIX for Dummies Questions & Answers

The trouble with FIND .......

Afternoon, I have a problem with the FIND and GREP commands working together. The command that I am typing is this:- find . -name *.sql -print --- This finds all files with an SQL suffix I then want to examine all those files to check for the existence of a string in them. I am... (2 Replies)
Discussion started by: chorse
2 Replies

Featured Tech Videos