Score:0

Rsync: Include only specific files from all subdirectories

pe flag

One folder named android with an undefined number of subdirectories that contain multiple files, some of them are APKs. One folder named windows with an undefined number of subdirectories and multiple files, some of them EXE files.

I would like to use rsync to copy the whole folder structure, but only copy APK and EXE files, nothing else.

I am using the --exclude-from option of rsync for that, but the APK files are not copied at all. I used this line of the manpage in order to achieve what I want: The combination of "+ */", "+ *.c", and "- *" would include all directories and C source files but nothing else (see also the --prune-empty-dirs option)

This results in the following file:

+ /android/**/*.apk
+ /android/*/
- /android/*

But nothing is actually copied. Can someone point me in the right direction here?

Score:3
id flag

You have to match any file and directory from root to be included or excluded. And then, exclude all the rest. In your case, something like this:

➜  ~ find /tmp/source 
/tmp/source
/tmp/source/no2
/tmp/source/no1
/tmp/source/no3
/tmp/source/android
/tmp/source/android/no5
/tmp/source/android/yes1.apk
/tmp/source/android/no6
/tmp/source/android/no7
/tmp/source/android/dir1
/tmp/source/android/dir1/no9
/tmp/source/android/dir1/yes2.apk
/tmp/source/android/dir1/no8
/tmp/source/android/dir1/dir2
/tmp/source/android/dir1/dir2/yes3.apk
mkdir /tmp/destination

rsync \
    -f "+ /android/" \
    -f "+ /android/*.apk" \
    -f "+ /android/**/" \
    -f "+ /android/**/*.apk" \
    -f "- /**" \
    -av \
/tmp/source/ /tmp/destination/

Et voilà:

sending incremental file list
./
android/
android/yes1.apk
android/dir1/
android/dir1/yes2.apk
android/dir1/dir2/
android/dir1/dir2/yes3.apk
Nidhoegger avatar
pe flag
Awesome! Thank you very much!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.