[K12OSN] OT: bash help - copying a series of files

David L. Willson DLWillson at TheGeek.NU
Fri Dec 12 18:15:22 UTC 2008

I think something like below might be a complete, automatable solution, but ...  well, actually, two of the files you want to backup have the same name, so no, this won't work either, because the identically-named files will clobber each other.  Specifically, the second "Drawings.desktop" overwrites the first.

Hmm...  So, you want to backup a tree, in order to avoid files with identical names clobbering each other, but you only want to backup files matching a certain pattern.  Yes?  Or, you have an entirely arbitrary list of files to copy, ~and~ you need them copied with path, so they don't clobber one another?

This is my proposal so far, but we have to keep the paths in somehow, and I'm not sure how to do that.

let myBackupFolder=$HOME/backups

if [ ! -d $myBackupFolder]; then mkdir $myBackupFolder; fi

if [ -w $myBackupFolder]; then
   cd /usr/local/share/icons && \
   find -iname Drawing*.desktop -exec cp -v {} $myBackupFolder \;

----- Original Message -----
From: "Rob Owens" <rob.owens at biochemfluidics.com>
To: "Support list for open source software in schools." <k12osn at redhat.com>
Sent: Friday, December 12, 2008 6:09:41 AM GMT -07:00 US/Canada Mountain
Subject: Re: [K12OSN] OT:  bash help - copying a series of files

Nils Breunese wrote:
> Rob Owens wrote:
>> j.w. thomas wrote:
>>> Rob Owens wrote:
>>>> I've read this somewhere before, but I'm having trouble finding it on
>>>> google...
>>>> I need to copy a series of files without using a loop.  I think the
>>>> syntax is something like:  cp /path/to/[file1 file2]
>>>> /destination/folder
>>>> But that doesn't work.  Does anybody know the correct syntax?  Google
>>>> isn't so good at searching special characters like [ and {
>>> I do this:
>>> cp /path/to/file1 /path/to/file2 /destination/folder
>>> If the names are as similar as you wrote though, you should be able to
>>> do this:
>>> cp /path/to/file[12] /destination/folder
>> The names really aren't that similar.  Here's the actual paths that I
>> need to copy:
>> /usr/local/share/icons/Drawings.desktop
>> /usr/local/share/icons/Obsolete\ Drawings.desktop
>> /usr/local/share/icons/Obsolete\ a\ Drawing.desktop
>> Since it's only 3 files, I could do as Robert suggests:
>>> cp  /path/file1  /path/file2  /path/file3  /dest/dir
>> But I was hoping to find a way with less typing, just in case someday I
>> have to do this with 10 files instead of 3.
> You could first change the current working directory, so you don't need
> to supply the path to every file.
>     cd /usr/local/share/icons
>     cp Drawings.desktop Obsolete\ Drawings.desktop Obsolete\ a\
> Drawing.desktop /dest/dir
That would work, but how do I error check?  I'd like some verification
that the cd worked before cp'ing (because what if I was rm'ing instead?)

I've done the job that I needed to do, but for my own betterment I'm
still interested in hearing ideas.



The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. If you are not the addressee, any disclosure, reproduction,
copying, distribution, or other dissemination or use of this transmission in
error please notify the sender immediately and then delete this e-mail.
E-mail transmission cannot be guaranteed to be secure or error free as
information could be intercepted, corrupted lost, destroyed, arrive late or
incomplete, or contain viruses.
The sender therefore does not accept liability for any errors or omissions
in the contents of this message which arise as a result of e-mail
transmission. If verification is required please request a hard copy


K12OSN mailing list
K12OSN at redhat.com
For more info see <http://www.k12os.org>

More information about the K12OSN mailing list