Score:1

Copy selected files from one folder, retaining the directory structure

cn flag
SEU

I want to copy all the JPG files from one folder to another and it works.

find /path/from/dirA/ -name "*.JPG" -exec cp "{}" /path/to/dirB \;

To improve on the above, I would like to copy them into the same directory structure with the date. The folder structure is like below without specifying the dates.

/path/from/dirB/2022_12_27  to  /path/to/dirB/2022_12_27
/path/from/dirB/2022_12_27  to  /path/to/dirB/2022_12_28

How do I go about creating the directory structure in /path/to/dirA, and also retain the file attributes?

Thanks.

sudodus avatar
jp flag
`rsync` is a tool, that can do what you want, locally as well as via a network. You can start by reading some tutorial via the internet, and then use the manual `man rsync` as a dictionary to recall the details ... This is a general example: `sudo rsync -Havn source/ target`; The slash after 'source' is important. It shows a dry run showing what will be done when you remove the option `n`.
cn flag
SEU
Thanks works well.
sudodus avatar
jp flag
I'm glad that I could help you start using `rsync` :-)
Andrej Podzimek avatar
cn flag
`rsync` is an immense overkill for this task though, in a sense. What you could also do is something along the lines of `cd /path/from/dirA; tar -c $(find . -name '*.JPG') | (cd /path/to/dirB; tar -x;)`.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.