1

I have a following directory structure (assume no two files have the same name):

  • Apple1
    • apple1.jpg
    • apple2.jpg
  • Apple2
    • apple3.jpg
    • apple4.jpg
  • Apple3
  • Tomato
  • Peach

And i would like to move one directory to the top directory all the *.jpg files inside the directories, which names start from Apple.

As a result I expect the Apple directories to be empty and the images from Apple directories to be in the top.

I have tried doing like mv "Apple*/*.jpg" ., or find . "Apple*/*.jpg" -exec mv -t . {} + as prescribed here How to integrate mv command after find command?. But this doesn't work.

When executing mv i receive a following message:

mv: cannot stat ‘Apple*/*.jpg’: No such file or directory

Seems like it has not found anything matching the pattern. And other option simply outputs nothing. Maybe the reason is, that in the case of subdirectories regular expression needs to be modified?

I would be very grateful for help and suggestions.

9
  • 1
    A picture is worth ~ 1k words, so post a tree diagram of what you want the post-move dir structure to look like.
    – guest_7
    Mar 20 '21 at 10:27
  • @guest_7 I would like to simply move all the images to the root directory as I've mentioned Mar 20 '21 at 10:29
  • What is the error you get when you run the move command mv Apple*/*.jpg .?
    – guest_7
    Mar 20 '21 at 10:32
  • 1
    What do you mean that it doesn't work? What you currently doesn't show enough regarding what you want to do. Mar 20 '21 at 10:32
  • 2
    You need to remove those quotes from the move command for the globbing to happen.
    – guest_7
    Mar 20 '21 at 10:41