I have an iBasso digital music player and I need a little help uisng rsync. I want to copy all of my muisc from /home/garrett/Music/ into my SD card which is at /media/garrett/6BF6-AC8A/ I'm currently using the command rsync -a --delete /home/garrett/Music/ /media/garrett/6BF6-AC8A/ The thing is I would also like to transfer my audio books which I don't keep in my music directory, they are in /home/garrett/Audiobooks/ I would like to add the audiobooks direcotry to the command above but instead of only coping the contents of the Audiobooks directory the way it's doing with my Music directory I would like it to copy the directory itself and it's contents, not just the contents. Secondly how do I keep the command listed above from deleting the Audiobook DIR everytime it runs, I need it to make an exception for the Audiobooks DIR. Thanks.

Dani AI

Generated

Short answer: include the Audiobooks tree in rsync’s source set (and give that source without a trailing slash) so rsync will create an Audiobooks directory on the card instead of only copying its contents. ’s symlink idea is workable, but it can be fragile with typical SD filesystems (vfat/exFAT) and when you run a reverse sync; treating Audiobooks as a real source is simpler and safer.

Template (single-command): give both sources and the destination; omit the trailing slash on the Audiobooks source so the directory itself is created on the card.

rsync -avh --delete /home/garrett/Music/ /home/garrett/Audiobooks /media/garrett/6BF6-AC8A/

Alternative (two-step): mirror Music with deletion, then sync Audiobooks separately (no deletion) so the Audiobooks folder on the card is left alone when the Music-only mirror runs.

rsync -avh --delete /home/garrett/Music/ /media/garrett/6BF6-AC8A/
rsync -avh /home/garrett/Audiobooks /media/garrett/6BF6-AC8A/

Notes and cautions: the trailing slash matters — a trailing slash copies only a directory’s contents, no slash copies the directory itself. Always run a dry run (-n) first to preview deletions. Check that the SD filesystem supports what you need: vfat/exFAT won’t preserve Unix permissions and may not handle symlinks or very large files, so avoid relying on symlinks if the card is FAT-based. Also verify free space and that the mount path is correct before committing a --delete run.

I believe that you should be able to create a symbolic link within your home Music directory that points to your Audiobooks directory. Then, you can run the rsync command on the Music directory and get both directories sync'ed at the same time. When running the reverse rsync command (from SD to home) you'll have to pass the -K or --keep-dirlinks option so that rsync doesn't destroy the symlink in the home Music folder to replace it with an actual directory, and instead it will follow the link and sync the SD's Audiobooks subfolder with your home's Audiobooks folder.

If you don't want to keep the symlink in your home Music folder, you could just write a simple bash script that creates the symlink, then runs rsync, and then removes the symlink right after. You can create a similar script on the SD card for when doing the reverse operation.

I'm not 100% sure that this will work, but it's worth a try (preferrable, test it with some "test" directories first, to make sure you don't lose your data if something goes wrong).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.