LinuxQuestions.org
Help answer threads with 0 replies.
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 10-07-2019, 12:04 PM   #1
Smokeyone
Member
 
Registered: Jul 2005
Location: uk
Distribution: trying mepis/knoppix/ubuntu
Posts: 71

Rep: Reputation: 15
command to find and move jpg's


Hello
I have searched the forum but am trying to find the command that will search through a folder with loads of sub folders through several layers and move all jpeg/jpg to another new folder and maybe rename any duplicate images/names..all folders are on an external hd
Many thanks

Last edited by Smokeyone; 10-07-2019 at 12:06 PM.
 
Old 10-07-2019, 12:18 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,140
Blog Entries: 3

Rep: Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551
Quote:
Originally Posted by Smokeyone View Post
Hello
I have searched the forum but am trying to find the command that will search through a folder with loads of sub folders through several layers and move all jpeg/jpg to another new folder
That would be a combination of the find and mv utilities. See their respective manual pages ...

Code:
man find
man mv
... and look at -type, -name, and -exec options for the former and the --backup=numbered option for the latter. Be sure your backup copies are good before experimenting on real images.

Quote:
Originally Posted by Smokeyone View Post
and maybe rename any duplicate images/names..all folders are on an external hd
That's harder. By what criteria will you decide that they are duplicate. It might be better to run a duplicate image detection program after copying. Geeqie, Fdupes, and Digikam could do that.
 
Old 10-07-2019, 01:30 PM   #3
Smokeyone
Member
 
Registered: Jul 2005
Location: uk
Distribution: trying mepis/knoppix/ubuntu
Posts: 71

Original Poster
Rep: Reputation: 15
I only meant rename duplicate images in the context of the same named file in different folders - not the image itself.
 
Old 10-07-2019, 03:36 PM   #4
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 3,012

Rep: Reputation: 836Reputation: 836Reputation: 836Reputation: 836Reputation: 836Reputation: 836Reputation: 836
Quote:
I only meant rename duplicate images in the context of the same named file in different folders
Look at:
man comm
man sort
man mv
man rename

Make 2 lists of files, one for each directory, then compare them.

You can list all .jpg in dir with
Code:
var1=$(ls *.jpg)
echo "$var1"
Example:
Code:
list1="
file1.jpg
file2.jpg
file3.jpg
"

list2="
file3.jpg
file4.jpg
file5.jpg
"

comm -12 --nocheck-order <(echo "$list1") <(echo "$list2")
file3.jpg
 
Old 10-08-2019, 04:25 AM   #5
Smokeyone
Member
 
Registered: Jul 2005
Location: uk
Distribution: trying mepis/knoppix/ubuntu
Posts: 71

Original Poster
Rep: Reputation: 15
I have been trying to get this to work -

find / -Folder1 "*.jpg" -type f -exec /bin/mv {} /Folder2/jpg \;
 
Old 10-08-2019, 04:29 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,140
Blog Entries: 3

Rep: Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551
The path must come first, before any of the options. Try this:

Code:
find /Folder1 -type f -name "*.jpg" -exec /bin/mv {} /Folder2/. \;
Note that there is an implied logical AND between each of the options if nothing is specified.

Code:
find /Folder1 -type f \( -name "*.jpg" -o -name "*.jpeg" \) -exec /bin/mv {} /Folder2/. \;
 
Old 10-08-2019, 05:31 AM   #7
Smokeyone
Member
 
Registered: Jul 2005
Location: uk
Distribution: trying mepis/knoppix/ubuntu
Posts: 71

Original Poster
Rep: Reputation: 15
Folder1 and Folder2 are both on my desktop

mint@mint-HP-Pro3500-Series:~/Desktop$ find . -type f \( -Folder1 "*.jpg" -o -iname "*.jpeg" \) -exec cp '{}' /Folder2 \;
find: unknown predicate `-Folder1'
mint@mint-HP-Pro3500-Series:~/Desktop$ find /Folder1 -type f -name "*.jpg" -exec /bin/mv {} /Folder2/. \;
find: /Folder1: No such file or directory
mint@mint-HP-Pro3500-Series:~/Desktop$ find /Folder1 -type f \( -name "*.jpg" -o -name "*.jpeg" \) -exec /bin/mv {} /Folder2/. \;
find: /Folder1: No such file or directory
 
Old 10-08-2019, 05:46 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,140
Blog Entries: 3

Rep: Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551
Then use whichever absolute path is appropriate for find and mv

Code:
find /home/smokeyone/Desktop/Folder1 -type f -name "*.jpg" \
        -exec /bin/mv --backup=numbered  {} /home/smokeyone/Desktop/Folder2/. \;
It would be the same path as you would use with ls to list the file names for either folder.
 
Old 10-08-2019, 07:05 AM   #9
Smokeyone
Member
 
Registered: Jul 2005
Location: uk
Distribution: trying mepis/knoppix/ubuntu
Posts: 71

Original Poster
Rep: Reputation: 15
Thank you very much for the help
 
Old 10-08-2019, 07:25 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,140
Blog Entries: 3

Rep: Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551Reputation: 2551
No problem.

Once you have it working, I'd recommend taking another look at the manual page and reviewing the options you just used:

Code:
man find
The page is long and a bit overwhelming at first but it is the authoritative reference on how to use the find utility so it is worth learning to navigate. This is a good opportunity to try it.
 
Old 10-08-2019, 09:52 AM   #11
Smokeyone
Member
 
Registered: Jul 2005
Location: uk
Distribution: trying mepis/knoppix/ubuntu
Posts: 71

Original Poster
Rep: Reputation: 15
Thanks for the suggestion - I will get to grips with man find -
Thanks again for the help
 
  


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
Images on SD card now .JPG, used to be .jpg terry-duell Fedora 7 05-17-2012 09:45 PM
Rename all ".JPG" files to ".jpg" under all subfolders... jiapei100 Programming 4 04-25-2010 06:27 PM
How can make FVWM support JPG? can't make jpg as my wallpaper. jazzi Linux - Desktop 5 08-09-2008 02:54 PM
HELP! BASH - Convert filenames from dsc00***.jpg to *.jpg jimmybond01 Programming 9 05-08-2007 06:17 AM
renaming all JPG to jpg quickk Linux - Newbie 8 09-05-2004 01:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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