[SATLUG] Help making a bash cp script

Enrique Sanchez esanchezvela.satlug at gmail.com
Mon Dec 27 14:55:10 CST 2010

On Sun, Dec 26, 2010 at 7:09 PM, Borries Demeler
<demeler at biochem.uthscsa.edu> wrote:
>> 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...

agree with rsync, though  : find <SRC> -print | cpio -pdvm NEWPATH ;
would copy <SRC> directory to <NEWPATH>/<SRC>, I'd stick to rsync as
cpio would skip existing files too but would not deal very well with
files that did not finish copying due to an interruption.

as far as deleting any empty directory, I'd would run a search and
pipe the output to rmdir, rmdir would only delete the directory if it
is empty, but
 DO NOT USE  rm -R

find <SRC> -type d -print | xargs rmdir

the only problem with this approach is that if you have
<PATH>/dir1/dir2/dir3 and no other files, then you would still end up
with dir1/dir2 directories

hope it helps.

More information about the SATLUG mailing list