Score:0

Recursively move certain folders to other folders of the same name

jp flag

I have the following structure:

dir1
 - subdir0
   - subfile00
   - subfile01
 - subdir1
   - subfile10
   - subfile11
 - file0
 - file1

dir2
 - subdir0
   - subfile00
   - subfile01
   - custom_file
 - subdir1
   - subfile10
   - subfile11
   - custom_file

I want to be able to move all the contents of dir1 to dir2 recursively but not delete custom_file in each folder.

I can script something that lists all of the files and move them individually but I was hoping the mv command had some option for this. Does anybody know of a clever command line trick for this?

Nmath avatar
ng flag
Whatever you end up coming up with, back up. I also suggest using `cp` instead of `mv` - you can make some pretty bad mistakes with both but `cp` is generally safer
uz flag
Jos
`rsync dir1 dir2` will do, followed by (if you're satisfied all has gone well) `rm -r dir1`.
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.