LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   command to find and move jpg's (https://www.linuxquestions.org/questions/linux-newbie-8/command-to-find-and-move-jpgs-4175662157/)

Smokeyone 10-07-2019 12:04 PM

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

Turbocapitalist 10-07-2019 12:18 PM

Quote:

Originally Posted by Smokeyone (Post 6044693)
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 (Post 6044693)
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.

Smokeyone 10-07-2019 01:30 PM

I only meant rename duplicate images in the context of the same named file in different folders - not the image itself.

teckk 10-07-2019 03:36 PM

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


Smokeyone 10-08-2019 04:25 AM

I have been trying to get this to work -

find / -Folder1 "*.jpg" -type f -exec /bin/mv {} /Folder2/jpg \;

Turbocapitalist 10-08-2019 04:29 AM

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/. \;

Smokeyone 10-08-2019 05:31 AM

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

Turbocapitalist 10-08-2019 05:46 AM

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.

Smokeyone 10-08-2019 07:05 AM

Thank you very much for the help

Turbocapitalist 10-08-2019 07:25 AM

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.

Smokeyone 10-08-2019 09:52 AM

Thanks for the suggestion - I will get to grips with man find -
Thanks again for the help


All times are GMT -5. The time now is 05:40 AM.