LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2010, 11:24 AM   #1
jiapei100
Member
 
Registered: Jan 2005
Location: Surrey, BC, Canada
Distribution: Ubuntu 12.04
Posts: 70

Rep: Reputation: 15
Rename all ".JPG" files to ".jpg" under all subfolders...


Hi, Dear all:

One question ! ^_^
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" "${x%.JPG}.jpg"; done "
works fine for me.

But how to recursively enter every subfolder and rename all the files?
(Well, if possible, enter every subfolder's subfolder.. recursively?? )

In sum, given a folder, all files under this folder, and all its subfolder, and all the subsubfolders, should be finally renamed in one specific rule.

How to deal with it?

Thank you very much and looking forward to your reply.

Best Regards
JIA Pei
 
Old 04-25-2010, 11:36 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,289

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
No scripting genius here but I think the approach is

for dirs in i do;
<do stuff>
next i

and it looks after the changing of directories (down) for you.
 
Old 04-25-2010, 11:44 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
find folder -name '*.JPG' -exec rename .JPG .jpg {} ;
 
1 members found this post helpful.
Old 04-25-2010, 01:19 PM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
find <dir> -name '*.JPG' -exec 'mv {} `echo {} | sed '/s/.JPG/.jpg/g'`'
Untested
 
Old 04-25-2010, 06:27 PM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Code:
find /path/to/directory -name '*.JPG' -exec rename 's/\.JPG/\.jpg/' '{}' \;
Worked, with some sample files.

Last edited by crts; 04-25-2010 at 06:30 PM.
 
0 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
please help with bash find / -name "*.sized.jpg" -exec rm -f {} ; rioguia Programming 4 01-16-2010 03:48 PM
Recursively add missing ".jpg" to all JPEG files. Chekote Linux - General 4 09-14-2009 11:45 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Cannot "Copy To" .jpg file to wallpaper folder LeanPudLou SUSE / openSUSE 5 11-08-2004 08:24 AM
"X-MS" cant open because "x-Multimedia System" cant access files at "smb&qu ponchy5 Linux - Networking 0 03-29-2004 11:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration