Rsync: Include only specific files from all subdirectories [closed]
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?
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