Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:29:56+00:00 2026-06-18T03:29:56+00:00

I am trying to create a bash script for syncing music from my desktop

  • 0

I am trying to create a bash script for syncing music from my desktop to a mobile device. The desktop is the source.

Is there a way to make rsync recursively sync files but ignore the directory structure? If a file was deleted from the desktop, I want it to be deleted on the device as well.

The directory structure on my desktop is something like this.

    Artist1/
        Artist1/art1_track1.mp3
        Artist1/art1_track2.mp3
        Artist1/art1_track3.mp3
    Artist2/
        Artist2/art2_track1.mp3
        Artist2/art2_track2.mp3
        Artist2/art2_track3.mp3
    ...

The directory structure that I want on the device is:

    Music/
        art1_track1.mp3
        art1_track2.mp3
        art1_track3.mp3
        art2_track1.mp3
        art2_track2.mp3
        art2_track3.mp3
    ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:29:58+00:00Added an answer on June 18, 2026 at 3:29 am

    Update: nov 2023

    1. Without find, by using bash‘s globstar

    Simply:

    rsync -a --delete --include=*.mp3 --exclude=* \
        pathToSongs/Theme*/Artist*/. destuser@desthost:Music/.
    

    would do the job if you’re path hierarchy has a fixed number of level.

    WARNING: if two song file do have exactly same name, while on same destination directory, your backup will miss one of them!

    If else, and for answering strictly to your ask ignoring the directory structure you could use bash‘s shopt -s globstar feature:

    shopt -s globstar
    rsync -a --delete --include=*.mp3 --exclude=* \
        pathToSongsRoot/**/. destuser@desthost:Music/.
    

    At all, there is no need to fork to find command.

    1.1 Recursively sync all files while ignoring the directory structure

    For answering strictly to question, there must no be limited to an extension:

    shopt -s globstar
    rsync -d --delete sourceRoot/**/. destuser@desthost:destRoot/.
    

    With this, directories will be copied too, but without content. All files and directories would be stored on same level at destRoot/.

    WARNING: If some different files with same name exists in defferents directories, they would simply be overwrited on destination, durring rsync, for finaly storing randomly only one.

    2. By using find

    When you use find, you may have to ensure special character in filenames to be correctly handled. For this you should use -print0 option to separate filenames by null chars (0x0), then tell rsync to read stdin by using null chars as separator:

    find first/source/path second/source/path -type f -name \*.mp3 -print0 |
        rsync -av0 --files-from - --no-relative . destuser@desthost:destRoot/.
    

    (Note the little 0 after -av, mean -a -v -0.)

    This syntax is based on relative path! If you plan to use full path you will use full path as find arguments and replace dot (current path) by a slash (root) in rsync command:

    find /first/source/path /second/source/path -type f -name \*.mp3 -print0 |
        rsync -av0 --files-from - --no-relative / destuser@desthost:destRoot/.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a FUNCTION in my Postgres database from a Bash script.
I am trying to create a BASH script what would extract the data from
I'm trying to create a simple bash script to get the HTTP codes from
I'm trying to make a script to create a .po files from my sources
I am trying to create a bash script to easily perform searches in logs
I am trying to create a bash script which passes its own argument onto
I am trying to create a shell script that pulls a line from a
Currently I'm trying to create a bash script for replacing new values I generated.
I am trying to create a bash script that is essentially like a magic
I am trying to create a bash script that will launch chromium, wait 20

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.