Rsync how to include directories but not files?

后端 未结 4 1465
半阙折子戏
半阙折子戏 2020-12-13 18:34

I have a directory structure and files like this

data/
data/a.txt
data/folder/
data/folder/b.txt
data/folder/folder/
data/folder/folder/c.txt
...


        
相关标签:
4条回答
  • 2020-12-13 19:08
    rsync -a -f"-! */" source/ destination/
    

    Filter rule means "Exclude anything that's not a directory."

    0 讨论(0)
  • 2020-12-13 19:18

    If you want to sync everything except one folder but you still want to keep the directory structure of that excluded folder, you should do the following:

    $ rsync -a -f"+ /var/log/**/*/" -f"- /var/log/**/*" source/ destination/
    

    See the exclude-list and the rsync command as an example.

    0 讨论(0)
  • 2020-12-13 19:24
    rsync -a --include='*/' --exclude='*' source/ destination/
    

    Basically, first include all directories, then exclude all files.

    0 讨论(0)
  • 2020-12-13 19:31
    $ rsync -a -f"+ */" -f"- *" source/ destination/
    

    "The two -f arguments mean, respectively, "copy all directories" and then "do not copy anything else"."

    Further details: http://psung.blogspot.com/2008/05/copying-directory-trees-with-rsync.html

    0 讨论(0)
提交回复
热议问题