You are not logged in.

#1 2009-01-08 22:00:42

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

[Solved] cp - If file exist, don't copy that file

Is there a way i can copy with cp that if a file exists, it won't even copy that file.

Last edited by haxit (2009-01-08 23:30:48)


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#2 2009-01-08 22:23:07

daf666
Member
Registered: 2007-04-08
Posts: 470
Website

Re: [Solved] cp - If file exist, don't copy that file

here:

yes n | cp -i src dest

edit: loool too late lol

Last edited by daf666 (2009-01-08 22:27:52)

Offline

#3 2009-01-08 22:23:54

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: [Solved] cp - If file exist, don't copy that file

Bash script was my last option big_smile I guess that is what I might have to do.

Last edited by haxit (2009-01-08 22:24:57)


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#4 2009-01-08 22:24:44

Nezmer
Member
Registered: 2008-10-24
Posts: 559
Website

Re: [Solved] cp - If file exist, don't copy that file

-- Edit --
Solution already mentioned .

'cp -i' or 'cp --interactive' should warn you before any overwrite .
For details :
man cp wink

Last edited by Nezmer (2009-01-08 22:26:42)


English is not my native language .

Offline

#5 2009-01-08 22:26:18

weasel8
Member
Registered: 2008-12-15
Posts: 149

Re: [Solved] cp - If file exist, don't copy that file

I assume you've already done man cp -- if the answer's not there, it may end up being a little more complex, like writing a little shell script or something.

You might try cp -i, which runs it interactively. So you get "cp: overwrite `<file>'?" for every file that's already in the target directory, but depending on how many files you have, that could get cumbersome.

EDIT: Wow, there were a ton of responses while I was typing this. tongue

Last edited by weasel8 (2009-01-08 23:04:13)

Offline

#6 2009-01-08 22:26:46

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] cp - If file exist, don't copy that file

yes n | cp -i

Offline

#7 2009-01-08 22:27:12

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: [Solved] cp - If file exist, don't copy that file

I will write up a bash script comparing files in current directory and directory i want to copy to. No biggie big_smile


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#8 2009-01-08 22:29:08

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: [Solved] cp - If file exist, don't copy that file

Not sure, but check the "u" option.


Have you Syued today?
Free music for free people! | Earthlings

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery

Offline

#9 2009-01-08 22:32:40

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] cp - If file exist, don't copy that file

finferflu wrote:

Not sure, but check the "u" option.

Here is an example: So it depends on the situation if it's usable.

$ echo AA > a
$ echo BB > b
$ cp -u a b
$ cat a b
: AA
: BB
$ echo BB > b
$ echo AA > a
$ cp -u a b
$ cat a b
: AA
: AA

Offline

#10 2009-01-08 22:52:06

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: [Solved] cp - If file exist, don't copy that file

finferflu wrote:

Not sure, but check the "u" option.

I think that is exactly what I am looking for! Thanks a lot. I didn't go THAT far down the man page tongue


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

Board footer

Powered by FluxBB