(SOLVED)How to sync files to a USB stick, INCLUDING DELETING

Forum rules
Before you post please read how to get help
Post Reply
User avatar
ericramos1990
Level 3
Level 3
Posts: 183
Joined: Sun Jul 21, 2013 11:54 am

(SOLVED)How to sync files to a USB stick, INCLUDING DELETING

Post by ericramos1990 »

Hey guys!

I have a question regarding a script I have to copy all of my music to my phone.

Code: Select all

cp -ruv /home/eric/music/* '/media/MyAndroid/Internal storage/music'
However, there is one additional thing I want to do.

If I delete some songs from my computer, how can I get this script to simply delete them from my phone as well?

I know I can do rm
'/media/MyAndroid/Internal storage/music'
and then
cp -ruv /home/eric/music/* '/media/MyAndroid/Internal storage/music'

But that will take an unneeded amount of time.

Please let me know if you don't understand what I am trying to ask, thanks guys I hope you have an answer!
Last edited by ericramos1990 on Thu Nov 14, 2013 9:02 pm, edited 1 time in total.
Keep on tuxin' =)

User avatar
ericramos1990
Level 3
Level 3
Posts: 183
Joined: Sun Jul 21, 2013 11:54 am

Re: How to update files to a USB stick, INCLUDING DELETING

Post by ericramos1990 »

Bumpiddy bump? O.o
Keep on tuxin' =)

User avatar
ericramos1990
Level 3
Level 3
Posts: 183
Joined: Sun Jul 21, 2013 11:54 am

Re: How to update files to a USB stick, INCLUDING DELETING

Post by ericramos1990 »

Final bump sorry guys
Keep on tuxin' =)

Habitual
Level 13
Level 13
Posts: 4863
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

Re: How to update files to a USB stick, INCLUDING DELETING

Post by Habitual »

ericramos1990 wrote:Hey guys!
I have a question regarding a script I have to copy all of my music to my phone.

Code: Select all

cp -ruv /home/eric/music/* '/media/MyAndroid/Internal storage/music'
However, there is one additional thing I want to do.
If I delete some songs from my computer, how can I get this script to simply delete them from my phone as well?
Use rsync with --delete option. Anything NOT found in /home/eric/music will be deleted from "Internal storage/music.

Code: Select all

rsync -avz /home/eric/music "/media/MyAndroid/Internal storage" --no-perms --delete
do a test...

Code: Select all

touch /home/eric/music/myfake.mp3
now rsync it with

Code: Select all

rsync -avz /home/eric/music "/media/MyAndroid/Internal storage" --no-perms
one of the very first files shown to be copied should be

Code: Select all

sending incremental file list
./
myfake,mp3
Now check for it with:

Code: Select all

find `pwd` "/media/MyAndroid/Internal storage" -name myfake.mp3 -type f
and that should spit out

Code: Select all

/media/MyAndroid/Internal storage/music/myfake.mp3
Now we are cooking with gas so, now delete the /home/eric/music/myfake.mp3 and use this from now on:

Code: Select all

rsync -avz /home/eric/music "/media/MyAndroid/Internal storage" --no-perms --delete
and everything NOT present in /home/eric/music will NOT be present in /media/MyAndroid/Internal storage after doing so.

adding an n to -avz (-avzn) will do a "dry-run".
so try that too before committing to using the --delete option of rysnc.

If you get nervous or stuck,. shoot me a PM and we'll go over it.

User avatar
ericramos1990
Level 3
Level 3
Posts: 183
Joined: Sun Jul 21, 2013 11:54 am

Re: How to update files to a USB stick, INCLUDING DELETING

Post by ericramos1990 »

Habitual, thank you sssoo much!

You honestly had to simply say the word "rsync" and I would have been perfectly fine researching it.

So thanks a lot for taking the time to make a whole tutorial on it I really appreciate it!

I tried it, and it is exactly what I wanted, I will immediately change it to solved!

I hope this helps others as well!
Keep on tuxin' =)

Habitual
Level 13
Level 13
Posts: 4863
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

Re: (SOLVED)How to sync files to a USB stick, INCLUDING DELE

Post by Habitual »

Glad it worked out.

Cammo
Level 2
Level 2
Posts: 59
Joined: Tue Apr 08, 2014 8:19 pm

Re: (SOLVED)How to sync files to a USB stick, INCLUDING DELE

Post by Cammo »

Hey Habitual, I know this is an old post, but thanks for the tutorial - helped me out too.

Habitual
Level 13
Level 13
Posts: 4863
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

Re: (SOLVED)How to sync files to a USB stick, INCLUDING DELE

Post by Habitual »

Cammo wrote:Hey Habitual, I know this is an old post, but thanks for the tutorial - helped me out too.
The mechanics of rsync haven't changed in ages, Glad this info helped you out.

Post Reply

Return to “Scripts & Bash”