How can I exclude all subdirectories but include files of a directory in rsync?
Solution 1:
Try this command:
rsync -a -f"- */" -f"+ *" /home/user/ destination/
man rsync
-f, --filter=RULE add a file-filtering RULE
The rule to include all files*
and exclude the dirs */
Another approach to use the regular copy cp
cp /home/usr/* /destination
you can get rid of the errors about dirs using redirection
cp /home/usr/* /destination 2>/dev/null
This will only copies the files inside your home without the directories
Solution 2:
If you want to solve this with --include
and --exclude
parameters, you should change the order of them: first exclude what you want, then include everything.
I do it usually with this command:
rsync -vazhP path/to/source path/to/dest --exclude '*/*/' --include '*'