How to copy only selected files from memory card to local drive with preserving directory structure.

Hi I am Rupesh from India and I am using android phone with memory card and a laptop with open suse leap 15.0 linux installed. I want to copy only selected files ie., with extension .mp3 from memory card to local drive.

I have a memory card with directory called music and it has sub directories which contains .m4a and .mp3. This particular directory called music is of size 100 GB. Most of the files are with extension .m4a with size 70 GB and remaining files are with extension .mp3 with size 30 GB.

Actually what my intention is to copy only only files with extension .mp3 and skip remaining files with extension .m4a. I also want to preserve the directory structure present in memory card.

In my hard drive I have a partition with 50 GB of free space. I have created a directory called copied.

In Linux we can create a small script which does the above but I don’t know shell scripting. At present I am engaged in some other work and I don’t have time to learn shell scripting.

I want a script with name copying with syntax.

copying /sdcard/music /run/media/root/source/copied

If possible can anyone of you write a script and provide or is there any program in Linux which does the above.

That would be absolute nonsense to write a script for it, since it can be done with a simple oneliner:


cp -a /sdcard/music/*.mp3 /run/media/root/source/copied/

And once again: we’re not some kind of script factory, we’re support forums. Where all are volunteers doing this is their own spare time. You could have googled this easily and google would even have provided you with the syntax of the command. Please take this in consideration.

It neither copies files in sub-directories, nor preserves directory structure. But rsync does do what is needed without scripting.

Ok I can’t achieve what I want through cp command but I can through rsync.

I requested a script but it’s not mandatory. What I want is a command which does what I want or if possible a GUI program.

Up to now I don’t know about rsync but some of you suggested which is helpful to me. Try to reply like this which can save many hours of my time.


rsync -avz /sdcard/music/ /run/media/root/source/copied/ --exclude=*.m4a

If you want the “music” folder itself copied as well, omit the “/” at the end

OK I can’t achieve what I want through cp command but I can through rsync.

I have requested a script but it’s not mandatory. Whatever I post its not a demand but I may be seeking your opinions.

Previously I don’t know about rsync but some of you suggested which is helpful to me. Try to reply like this which can save many hours of my time.

If an Android mobile telephone and, the Linux desktop is KDE Plasma then, use KDE Connect.

  • It’s installed by default on openSUSE KDE Plasma desktops.
  • Pull it from the Google Play Store onto your Android telephone.
  • Connect the telephone to the WLAN associated with the LAN or WLAN where your KDE Desktop is connected.
  • Et voilà ! – Your mobile telephone is integrated with your KDE Plasma Desktop …

More information here: <https://kde.org/applications/internet/org.kde.kdeconnect.kcm> and here: <https://community.kde.org/KDEConnect>.
The handbook is here: <https://docs.kde.org/stable5/en/extragear-network/kdeconnect-kde/index.html>.
[HR][/HR]More than a few users simply leave their telephone out of sight somewhere and control everything going on, except actually holding a telephone conversation – « Who does that these days? » – via their desktop …

Hi I found somewhere the following code

find . -name "*mp3" -type f -exec cp -p --parents {} /path/to/copy/to \;

Can you examine whether it is correct or not

I tested and found it does what you presumably expect. You may want to replace ‘-p’ with ‘-a’.

For the case of “find”, you could consider using ‘-iname’ in place of ‘-name’ to work around any Upper/Lower case issues.
Further for the case of “find”, please be aware that, the complete path name of the command to be executed by ‘-exec’ is preferred over the “usual”, path dependent, command characters.
Further for the case of “find”, please be aware that, the ‘-exec’ parameter {} often needs be enclosed in single quotes – ‘{}’ …

[size=3]

Rupesh, I have to agree with Knurpht, and add that your question itself is incredibly rude. YOU want to accomplish something, and tell us that you don’t have time to do it, then expect us to do it for you? Also, you have been playing this “I don’t know scripting/I am very new/I don’t have time” card for YEARS at this point, not only here but on other forums where it got you banned. A simple search here tells me you’ve been asking about scripts for 3 years; why, in all that time, have you been unable to learn the very basics? Bash tutorials are everywhere, and a simple loop is all that’s needed. A Google search for your user ID and “linux script” tells me that you’ve been asking for scripts for 7 yrs. at least.

Why, WHY can you not show efforts of your own, after so many years?

**Later:
**

Again it’s WE should save you many hours of time, which will take up OUR time. Instead of that, why can’t you learn how to script yourself after so many years? If you spent as much time learning scripting as you do with your hand out, asking people to write them for you, you’d have been a pro years ago. Bear in mind people on forums don’t care if you are ‘busy’, since we volunteer our time to help others.

And saying you didn’t know about rsync is a plain lie, since you’ve been told about it many times in the past, when you’ve asked near-identical questions, always involving a bunch of sound files, and wanting to bulk copy/move/download them.
https://forums.opensuse.org/showthread.php/526857-How-to-create-a-database-for-the-contents-of-folder-containing-11000-mp3-files?highlight=rsync

**And later:
**

It took you longer to post this than it would have for you to run it, and find out. [/size]

I called him out once before, as you are doing now, and nothing has been done about that account. I have a sneaking suspicion that the account is used by multiple users.

Meaning that, we’re being used a teachers?

  • Which is possibly OK for things specific to openSUSE but, I have my reservations with respect to things which are specific to UNIX® and/or Linux in general …
  • Meaning, there’re people on this planet who are earning their living by teaching general UNIX® and/or Linux knowledge «Bash, Awk, Sed, Vi, Grep, etc., etc. … ».

I was thinking more like an open computer in a classroom where their class has this single account.
It’s the only thing I can see to explain his continuous request for us to do his “homework”.

But in the end, yes, like we’re being used as teachers.

Though I understand your reasoning, please let’s not go assuming things etc, I’ll close the thread now, since the OP has had enough advice to solve their issue.