LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 09-04-2004, 11:43 AM   #1
quickk
Newbie
 
Registered: Jul 2003
Posts: 15

Rep: Reputation: 0
renaming all JPG to jpg


Hi there,

I was wondering how I can change all the files with "JPG" extension to "jpg". I want to change the extensions in the folder the command executed plus all the subfolders.

Thanks
 
Old 09-04-2004, 01:07 PM   #2
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 47
for f in *.JPG; do mv $f `echo $f|sed 's/JPG/jpg/'`;done
 
Old 09-04-2004, 01:13 PM   #3
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
I realize this is not my thread, but it may beneficial to people (me included) to know exactly what that means. Could you break it down please?
Also:
Quote:
the command executed plus all the subfolders
Will that command do it recursively?

Last edited by scuzzman; 09-04-2004 at 01:16 PM.
 
Old 09-04-2004, 01:20 PM   #4
red_over_blue
LQ Newbie
 
Registered: Feb 2003
Location: MB, Canada
Posts: 26

Rep: Reputation: 15
You could also:

Code:
rename -v 's/JPG/jpg/' *.JPG
 
Old 09-04-2004, 01:20 PM   #5
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 47
Code:
for f in *.JPG; // select all the JPG filenames and save it in the variable f
do 
    mv $f `echo $f|sed 's/JPG/jpg/'`;
    // mv ... the move command ...
    //  `echo $f|sed 's/JPG/jpg/'` (note the backquote) here sed is used to replace JPG with jpg.
    //  echo is used to provide the filename string to sed. 
done
 
Old 09-04-2004, 01:33 PM   #6
red_over_blue
LQ Newbie
 
Registered: Feb 2003
Location: MB, Canada
Posts: 26

Rep: Reputation: 15
Didn't noticed the original post asked for recursion. Here is yet another command that will perform what you want:

Code:
find ./ -name "*.JPG" -exec rename -v 's/JPG/jpg/' {} \;
 
Old 09-04-2004, 01:41 PM   #7
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
You could use variable substitution:

for file in *.JPG; do mv "${file}" "${file%.JPG}.jpg"; done

This will operate on a single directory. The double quotes around the variables are needed
for the case when the file name contains spaces.
 
Old 09-04-2004, 03:25 PM   #8
quickk
Newbie
 
Registered: Jul 2003
Posts: 15

Original Poster
Rep: Reputation: 0
Hi there,

Thank you very much for replying. I couldn't fix the problem though. I don't know why but none of them works. I copied and pasted every one of them. they don't work even within directory(not including subdirectories). maybe the reason is jailshell. I don't know. I will try to change them manually.

thank you very much
 
Old 09-05-2004, 02:23 AM   #9
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 47
you can lsattr to find out if any immutable properties have been set.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How do I change HTML to jpg? akihandyman Mandriva 4 05-20-2004 11:42 AM
BMP to JPG how to merlin371 Programming 7 01-10-2004 06:59 PM
Jpg EmmettHR Mandriva 2 10-05-2003 08:41 AM
ps to jpg marcoc Linux - Newbie 2 04-08-2002 01:24 PM
.jpg to .avi ??? ddpicard Linux - General 7 12-08-2001 12:02 AM


All times are GMT -5. The time now is 06:07 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration