[SATLUG] Help making a bash cp script

Borries Demeler demeler at biochem.uthscsa.edu
Sun Dec 26 18:09:23 CST 2010

> I have to say I'm terrible at coding, so I thought I might ask here. All I
> want to do is copy a large group of mp3's to an external drive using the cp
> command. The total size is about 28GB~. In copying over all of the files
> though, I want to remove any empty directories. Old empty albums for
> example. I've been googling a little bit, trying to find a similar script to
> butcher apart and use for my own devices, but haven't had any luck. Does
> anyone have any ideas on where I should go with this?

rsync is your friend...

Here is a basic example on how to do it:

first, mount your harddrive:

mount /dev/sdxn /mnt  

("x" is the external harddrive device number, "n" is the partition number, if
you don't know what x or n is, simply type "dmesg" after plugging in the external drive
and look towards the bottom of the message, it should say the name)

Then go into the directory with your mp3 files:

cd /my/mp3/files

then synchronize the files in the mp3 directory with the harddrive mounted under /mnt:

rsync -auv * /mnt/.

If you have a subdirectory on your harddrive, you could easily copy there as well:

rsync -auv * /mnt/mp3/backup/directory/.

The nice thing about this approach is that if you add a couple of new mp3's to 
/my/mp3/files then you can repeat the rsync command and it will only copy the new
files, making the new backup very quick and efficient. This even works over a slow
network connection.

Cheers, -b.

More information about the SATLUG mailing list