LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-14-2009, 11:56 AM   #1
Chekote
LQ Newbie
 
Registered: Apr 2007
Posts: 3

Rep: Reputation: 0
Recursively add missing ".jpg" to all JPEG files.


I'm trying to search a volume for all JPEG files without a jpeg extension, and add it.

I found a lot of similar questions, which were a great deal of help, but I've ran into a problem with my command.

This is what I have so far:

Code:
find . -type f -exec file {} \; | grep JPEG | grep -vi ".jpg" | cut -d ":" -f1 | xargs -0 -t -I "{}" mv {} {}.jpg
Everything works fine up to the xargs, at which point I end up with the following error:

Code:
mv: rename {} to {}.jpg: No such file or directory
Obviously I'm not populating the {} parameter correctly, even though this command works fine without the "find" at the beginning:

Code:
file * | grep JPEG | grep -vi ".jpg" | cut -d ":" -f1 | xargs -t -I "{}" mv {} {}.jpg
I almost had this working without having to post another thread. v_v

Thanks in advance for the help.

Last edited by Chekote; 09-14-2009 at 11:57 AM.
 
Old 09-14-2009, 02:16 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
'{}'
 
Old 09-14-2009, 03:11 PM   #3
ramram29
Member
 
Registered: Jul 2003
Location: Miami, Florida, USA
Distribution: Debian
Posts: 848
Blog Entries: 1

Rep: Reputation: 47
I've had the same problem. Try this:

find . -type f -exec file {} \; | grep -e JPEG -e "\.jpg" | awk -F : 'print {$1}' | while read i; do mv $i $i.jpg; done
 
Old 09-14-2009, 06:25 PM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by Chekote View Post
I'm trying to search a volume for all JPEG files without a jpeg extension, and add it.

I found a lot of similar questions, which were a great deal of help, but I've ran into a problem with my command.

This is what I have so far:

Code:
find . -type f -exec file {} \; | grep JPEG | grep -vi ".jpg" | cut -d ":" -f1 | xargs -0 -t -I "{}" mv {} {}.jpg
Everything works fine up to the xargs, at which point I end up with the following error:

Code:
mv: rename {} to {}.jpg: No such file or directory
Obviously I'm not populating the {} parameter correctly, even though this command works fine without the "find" at the beginning:

Code:
file * | grep JPEG | grep -vi ".jpg" | cut -d ":" -f1 | xargs -t -I "{}" mv {} {}.jpg
I almost had this working without having to post another thread. v_v

Thanks in advance for the help.
Quote:
I'm trying to search a volume for all JPEG files without a jpeg extension, and add it.
In computer science you need to spell things out. Tell us what extensions the files do have. The only way to unambiguously rename the files is if we know what name they have now.

For example, if you have a bunch of files that had [filename].JPEG as a name, and you wanted them to be renamed [filename].jpg, you would do this:

Code:
path="/path/of/interest"

find $path -type f | grep -P "\.JPEG$" | while read oldpath
do
   newpath=${oldpath//.JPEG}.jpg
   echo "testing: mv $oldpath $newpath"
   # mv $oldpath $newpath
done
(After testing and satisfying yourself that the script works, uncomment the commented line "mv $oldpath $newpath".)

But remember to think very clearly about the problem to be solved. That way you don't run a bunch of pointless code, solving nonexistent problems.

And whatever you do, avoid the use of "xargs" in any context whatsoever. The longest, most pointless threads in this discussion board revolve around attempts to use "xargs", and they frequently result in the original poster either being led away by men in white coats, or leaping off a cliff.

I cannot confirm the rumor that "xargs" was written by Bill Gates in order to undermine the entire Linux establishment, but based on the content of these discussion boards, it's working.

Quote:
Everything works fine up to the xargs ...
Famous last words.

Last edited by lutusp; 09-15-2009 at 03:26 AM. Reason: Corrected wrong variable name
 
Old 09-14-2009, 11:45 PM   #5
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
like semicolon braces should be escaped too:
Code:
\{\}
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove Folders Recursively that contain *.mp3 files size 0KB or jpeg only. Drigo Linux - Newbie 1 07-15-2009 12:37 AM
xmame problems "ERROR: required files are missing" GT_Onizuka Linux - Games 14 09-19-2007 02:10 AM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
shell script to recursively "compare" all files in a directory... silex_88 Programming 3 05-12-2007 04:24 AM
add "Artist" and "Album Title" to mp3 files powah Linux - Software 2 04-05-2005 03:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:17 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