rsync only *.php files
12,873
The culprit here is the
--include '*/'
When including a wildcard followed by the trailing forward-slash you're telling rsync to transfer all files ending with a '/' (that is, all directories).
Thus,
rsync -v -aze 'ssh ' \
--numeric-ids \
--delete \
--exclude '*' \
--include '*.php' \
[email protected]:/home/www/domain.com \
/Volumes/Servers/
If you were using that because you intend to recursively find all .php files, you’d have to use the ** wildcard.
That is,
--include '**/*.php'
Another way ( http://www.commandlinefu.com/commands/view/1481/rsync-find ) is pre-finding the target files and then using rsync,
find source -name "*.php" -print0 | rsync -av --files-from=- --from0 ./ ./destination/
Author by
Poe
Updated on June 28, 2022Comments
-
Poe almost 2 years
How can I rsync mirror only *.php files? This gives me a bunch of empty dirs too and I don't want those.
rsync -v -aze 'ssh ' \ --numeric-ids \ --delete \ --include '*/' \ --exclude '*' \ --include '*.php' \ [email protected]:/home/www/domain.com \ /Volumes/Servers/
-
Poe over 11 yearsThe rsync command excluded all files, so nothing was transferred. I think what I did was use the original block I tried, and just ran a find command to delete all empty folders when it finished.
-
G-Wiz over 10 yearsYeah, the catch-all
exclude
should come after theinclude
. -
Michael over 3 years@G-Wiz Well I wish the answer actually said that - although I can't get it to work either way.