• Uncategorized

About linux : Rsync-how-to-include-directories-but-not-files

Question Detail

I have a directory structure and files like this


a.txt, b.txt, and c.txt are large files that are computer-generated and renewed frequently. They should NOT be backuped — but I want to backup the directory structure :


How can I do this with rsync and –exclude-from, without specifying every folder, but something like rsync -a data/* --exclude-from=exclude.rsync "" --onlyfoldersandnotfiles""?

Thanks for help !

Question Answer

rsync -a --include='*/' --exclude='*' source/ destination/

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

$ 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

rsync -a -f"-! */" source/ destination/

Filter rule means “Exclude anything that’s not a directory.”

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.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.