include file with rsync

whired123

Member
Joined
Nov 15, 2021
Messages
61
Reaction score
4
Credits
480
Bash:
+ tree src
src
├── invoice.pdf
├── private-resources
│   ├── attachment1.pdf
│   ├── attachment2.pdf
│   └── attachment3.pdf
└── receipt.pdf

+ rsync -nai --include private-resources/attachment2.pdf --exclude 'private-resources/*' \
    src/ \
    dest
>f+++++++++ invoice.pdf
>f+++++++++ receipt.pdf
cd+++++++++ private-resources/
>f+++++++++ private-resources/attachment2.pdf

mmmhhh...

But I wanted it private-resources/attachment2.pdf to be copied to the root directory, that is, the output I expected is the following

Bash:
>f+++++++++ invoice.pdf
>f+++++++++ receipt.pdf
>f+++++++++ attachment2.pdf

Yes you can?
 


To copy private-resources/attachment2.pdf to the root directory of dest, you can use the following rsync command:

Code:
rsync -nai --include 'private-resources/attachment2.pdf' --exclude 'private-resources/*' \
    --prune-empty-dirs --relative src/ dest/

This command uses the --relative option to preserve the directory structure of the included files, and --prune-empty-dirs to remove any empty directories created by the --relative option. This way, attachment2.pdf will be copied to the root directory of dest.
 
To copy private-resources/attachment2.pdf to the root directory of dest, you can use the following rsync command:

Code:
rsync -nai --include 'private-resources/attachment2.pdf' --exclude 'private-resources/*' \
    --prune-empty-dirs --relative src/ dest/

This command uses the --relative option to preserve the directory structure of the included files, and --prune-empty-dirs to remove any empty directories created by the --relative option.
....mmmhhh....
This way, attachment2.pdf will be copied to the root directory of dest.
Bash:
tmp.lCjneYUOuY$ rsync -nai --include 'private-resources/attachment2.pdf' --exclude 'private-resources/*' \
    --prune-empty-dirs --relative src/ dest/
>f+++++++++ src/invoice.pdf
>f+++++++++ src/receipt.pdf
cd+++++++++ src/private-resources/
>f+++++++++ src/private-resources/attachment2.pdf
mmmhhh
 
Obviously the original file will still be there. Also you need to change the destination to whatever you want it to be.

/ or /root
 
I think we're not understanding each other very well...

Instead of this result

Code:
dest
├── invoice.pdf
├── private-resources
│   └── attachment2.pdf
└── receipt.pdf

I would like this

Code:
dest
├── invoice.pdf
├── attachment2.pdf
└── receipt.pdf
 

Staff online

Members online


Top