copy all files with jpg/jpeg extension in specific sub categories to single directory

0

I have a directory structure as below

  • product_images
    • product1
      • LR
        • low res images here
      • HR
        • high res images here
    • product2
      • LR
        • low res images here
      • HR
        • high res images here
    • product3
      • LR
        • low res images here
      • HR
        • high res images here

I want to copy all images with extension jpg/jpeg in the HR folders to a single directory.

I tried to modify find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec cp '{}' /cpjpg \; but nothing seems to be working.

hirani89

Posted 2019-07-04T06:13:00.660

Reputation: 1

Remove the quotes around {}. – xenoid – 2019-07-04T07:07:28.983

I tried to modify … but nothing seems to be working. – Did you get any feedback? Please [edit] the question and include the exact (modified) command(s) and error messages they print (if any). The "base" command looks sane but it may "succeed" in a somewhat confusing way when /cpjpg is not a directory or it doesn't exist initially. So make sure your target is a directory. – Kamil Maciorowski – 2019-07-04T16:50:37.357

@xenoid I think the quotes don't make a difference. Why do you think they do? – Kamil Maciorowski – 2019-07-04T16:51:03.880

Answers

0

You could do:

find . -type f -ipath "*/HR/*.jp*g" -exec cp -i {} /cpjpg \;

I used cp -i to not automatically overwrite existing files.

Freddy

Posted 2019-07-04T06:13:00.660

Reputation: 1 204