admin管理员组

文章数量:1125616

I want to sync from source to dest, only pass those files with postfix "*.gz"

the tree command of tree root@tt:/source is

/source
├── 20250108
│   └── tt
│       ├── binance
│       │   └── swap
│       │       └── bookticker
│       │           ├── 1000000MOG_USDT.20250108.bin.gz

I tried:

rsync -avP -n -f "+ */*/*/*/*/*.gz" -f "- *" root@tt:/source /dest
rsync -avP -n -f "+ *.gz" -f "- *" root@tt:/source /dest

above two commands matchs none.

could you help on this? ps. i want to keep the directories tree structure, also.

I want to sync from source to dest, only pass those files with postfix "*.gz"

the tree command of tree root@tt:/source is

/source
├── 20250108
│   └── tt
│       ├── binance
│       │   └── swap
│       │       └── bookticker
│       │           ├── 1000000MOG_USDT.20250108.bin.gz

I tried:

rsync -avP -n -f "+ */*/*/*/*/*.gz" -f "- *" root@tt:/source /dest
rsync -avP -n -f "+ *.gz" -f "- *" root@tt:/source /dest

above two commands matchs none.

could you help on this? ps. i want to keep the directories tree structure, also.

Share Improve this question asked Jan 9 at 6:33 nothingismenothingisme 1215 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To sync files with the .gz postfix from the source to the destination while preserving the directory structure, you can use the following rsync command:

rsync -avP --include='*/' --include='*.gz' --exclude='*' root@tt:/source/ /dest

--include='*/' includes all directories, --include='*.gz' includes all .gz files, and --exclude='*' excludes all other files.

This command ensures that only .gz files are transferred, and the directory structure is preserved.

本文标签: linuxHow to select all files with certain postfix in all subdirectories in certain directoryStack Overflow