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

Forum rules
Before you post please read this

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

Postby ericramos1990 on Wed Nov 06, 2013 2:01 am

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: 150
Joined: Sun Jul 21, 2013 11:54 am

Linux Mint is funded by ads and donations.
 

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

Postby ericramos1990 on Fri Nov 08, 2013 2:44 pm

Bumpiddy bump? O.o
Keep on tuxin' =)
User avatar
ericramos1990
Level 3
Level 3
 
Posts: 150
Joined: Sun Jul 21, 2013 11:54 am

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

Postby ericramos1990 on Thu Nov 14, 2013 5:22 pm

Final bump sorry guys
Keep on tuxin' =)
User avatar
ericramos1990
Level 3
Level 3
 
Posts: 150
Joined: Sun Jul 21, 2013 11:54 am

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

Postby Habitual on Thu Nov 14, 2013 8:06 pm

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.
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2219
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

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

Postby ericramos1990 on Thu Nov 14, 2013 9:01 pm

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' =)
User avatar
ericramos1990
Level 3
Level 3
 
Posts: 150
Joined: Sun Jul 21, 2013 11:54 am

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

Postby Habitual on Thu Nov 21, 2013 7:53 pm

Glad it worked out.
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2219
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

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

Postby Cammo on Fri May 02, 2014 11:40 pm

Hey Habitual, I know this is an old post, but thanks for the tutorial - helped me out too.
Cammo
Level 2
Level 2
 
Posts: 60
Joined: Tue Apr 08, 2014 8:19 pm

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

Postby Habitual on Wed May 07, 2014 12:10 pm

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.
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2219
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest