Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: UNIX command cp

RE: UNIX command cp

From: Toepke, Kevin M <ktoepke_at_cms.cendant.com>
Date: Mon, 15 Jan 2001 07:03:53 -0500
Message-Id: <10742.126655@fatcity.com>


Assuming you have files named file1, file2, file3 in a directory. If you "cp file* file*" this will get expanded to:

        cp file1 file2 file3
Which is intrepted as "cp file1 file2" or replace the existing file2 with a copy of file1.

On the other hand, if you say "cp file* dir1" (the destination being a directory), the copies of file1, file2, and file3 are placed in a dir1.

For safety, I always add an alias to my startup shell "alias cp='cp -i'", which means that cp will prompt you before overwriting!

Kevin

> -----Original Message-----
> From: yong huang [mailto:yong321_at_yahoo.com]
> Sent: Saturday, January 13, 2001 12:30 AM
> To: Multiple recipients of list ORACLE-L
> Subject: UNIX command cp
>
>
> I vaguely remember a long time ago somebody in a UNIX group
> says using wild
> cards in the cp command is dangerous, because after *
> expansion, the second
> file (the 2nd argument) gets overwritten by the first file
> (the 1st arg). Since
> then, I've always used
>
> for i in *; do
> cp $i $i.bak #or cp $i /somedir
> done
>
> But I can't reproduce that danger. Can anyone give an example?
>
> What triggered me to ask this is an interesting incident.
> Recently I inherited
> our production server and stayed late to test the cold backup
> script which I
> modified a little bit. From ps -ef | grep cp, I saw the command:
>
> cp /myoradatapath/system01.dbf /myoradatapath/system02.dbf
>
> Sweats came to my forehead!!
>
> What happens is that the C shell script the former DBA wrote
> is simply doing:
> cp /myoradatapath/* /anotherdir. But ps -ef only displays
> part of the expanded
> command.
>
> Anyway, can anyone give an example to show that cp * *.bak or the like
> overwrites files? Thanks.
>
> Yong Huang
> yong321_at_yahoo.com
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: yong huang
> INET: yong321_at_yahoo.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
Received on Mon Jan 15 2001 - 06:03:53 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US