0

Is possible with rsync to copy multiple files from a source directory to a dest directory with multiple subdirectories that don't exist? Or use install -D with multiples files to a directory that doesn't exist?

Also I looked at cp --parents but used the name of the source directory. Is it possible that cp can select a destination directory that doesn't exist and copy all files to it after it makes it?

I have this question: Copy a file to a directory that doesn't exist with only one command (Linux) Merge with: How can I copy a file and create the target directories at the same time?

But the solutions for copying one file, I looking at something like:

cp /etc/*.conf ~/mytest/ 

where mytest doesn't exist and /etc/*.conf is more than one file. Is it possible with cp and with only one command is better?

1

Try with rsync command:

rsync -av /etc/*.conf ~/mytest

In general you can use

rsync -av In/*conf Out/NewDir

The situation before is:

In
├── d1.conf
├── d2.conf
├── d3.txt
├── Sub_In_1
└── Sub_In_2.conf
    └── SubIn2.Files

Out
└── Out_OldFiles

After the command will be

Out
├── NewDir
│   ├── d1.conf
│   ├── d2.conf
│   └── Sub_In_2.conf
│       └── SubIn2.Files
└── Out_OldFiles

In this case you select not only common files *.conf but even directory Sub_In_2.conf. You will copy all the selection (files and directory) in a newly created directory NewDir below the Out directory.

The option -a include even the -r one (recurse into directories)

  -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)

Notes

  • The rsync recursive option is -r (and not -R).
  • In cp -r and -R correspond to the same option.
  • The option -v is not necessary it gives only some info more.
  • Withrsync you can be used even between 2 different computer using host1 for the origin host and host2 for the destination host.

The last command is

rsync  -av host1:InputDir host2:OutputDir/NewDirThatDidNotExists
  • This should be an edit to your exisiting answer... – jasonwryan May 8 '14 at 22:48
  • I start to answer before you modify and clarify the question. Now it is more clear, before it should be one of the 2 cases (slightly different)... More practical examples can help different people maybe... – Hastur May 8 '14 at 23:01
  • Compacted the answer is one. @jasonwryan Check if it's better now. For JHG Does it solve? – Hastur May 10 '14 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.