Score:0

Copy structure of dirs with files from file.txt

lk flag

I take output from this command to file.txt and have list of dirs.

find /path/ -type d > dirs.txt

Then I use next command to make this dirs in other location:

xargs mkdir -p < dirs.txt

Everythin work propably, but now I want to copy dirs with files from txt file to new location. What I should use to take thems?

For example

I got 2 trees of files in /path/dir

dir1
├── 1
│   └── file1
├── 2
│   └── file1
├── 3
│   └── file1
├── 4
│   └── file1
├── 5
    └── file1
dir2
├── 1
├── 2
├── 5

And I want take this structure of dir2 to file.txt and then copy dirs with files from dir1 to other location

HuHa avatar
es flag
Use `rsync` instead. I only today explained it [here](https://askubuntu.com/questions/1349296/copy-files-based-on-date-with-structure-of-directories/).
mechmati avatar
lk flag
I don't understand how use this `rsync` to take only specified files from dir1 using dir2
HuHa avatar
es flag
There is the `--files-from=FILE` command line option, and there is the opposite `--exclude=...` option.
mechmati avatar
lk flag
Thanks! I got this: `rsync -a /source/directory --files-from=/full/path/to/listfile /destination/directory`
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.