cp -Tr overwrite behavior
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I'm using GNU coreutils
I have a directory foo
containing a file file1
and a directory bar
containing file2
.
If I now do a cp -rT foo bar
, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.
I'd like for ôbarô only to contain the contents of ôfooô and not get merged.
shell cp
add a comment |Â
up vote
-1
down vote
favorite
I'm using GNU coreutils
I have a directory foo
containing a file file1
and a directory bar
containing file2
.
If I now do a cp -rT foo bar
, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.
I'd like for ôbarô only to contain the contents of ôfooô and not get merged.
shell cp
1
What part of the manual are you referring to? Is this using GNUcp
from coreutils, or some other implementation of thecp
command?
â Kusalananda
Sep 13 at 11:48
I'm referring totreat DEST as a normal file
. Normal files get overwritten when you copy over them. This is not the case here.
â Philippe
Sep 13 at 11:58
the contents of the files are irrelevant. I'm talking about the contents of the directories
â Philippe
Sep 13 at 12:15
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I'm using GNU coreutils
I have a directory foo
containing a file file1
and a directory bar
containing file2
.
If I now do a cp -rT foo bar
, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.
I'd like for ôbarô only to contain the contents of ôfooô and not get merged.
shell cp
I'm using GNU coreutils
I have a directory foo
containing a file file1
and a directory bar
containing file2
.
If I now do a cp -rT foo bar
, bar will contain both files instead of getting overwriten like the manpage might lead you to believe.
I'd like for ôbarô only to contain the contents of ôfooô and not get merged.
shell cp
shell cp
edited Sep 13 at 12:17
asked Sep 13 at 11:17
Philippe
10514
10514
1
What part of the manual are you referring to? Is this using GNUcp
from coreutils, or some other implementation of thecp
command?
â Kusalananda
Sep 13 at 11:48
I'm referring totreat DEST as a normal file
. Normal files get overwritten when you copy over them. This is not the case here.
â Philippe
Sep 13 at 11:58
the contents of the files are irrelevant. I'm talking about the contents of the directories
â Philippe
Sep 13 at 12:15
add a comment |Â
1
What part of the manual are you referring to? Is this using GNUcp
from coreutils, or some other implementation of thecp
command?
â Kusalananda
Sep 13 at 11:48
I'm referring totreat DEST as a normal file
. Normal files get overwritten when you copy over them. This is not the case here.
â Philippe
Sep 13 at 11:58
the contents of the files are irrelevant. I'm talking about the contents of the directories
â Philippe
Sep 13 at 12:15
1
1
What part of the manual are you referring to? Is this using GNU
cp
from coreutils, or some other implementation of the cp
command?â Kusalananda
Sep 13 at 11:48
What part of the manual are you referring to? Is this using GNU
cp
from coreutils, or some other implementation of the cp
command?â Kusalananda
Sep 13 at 11:48
I'm referring to
treat DEST as a normal file
. Normal files get overwritten when you copy over them. This is not the case here.â Philippe
Sep 13 at 11:58
I'm referring to
treat DEST as a normal file
. Normal files get overwritten when you copy over them. This is not the case here.â Philippe
Sep 13 at 11:58
the contents of the files are irrelevant. I'm talking about the contents of the directories
â Philippe
Sep 13 at 12:15
the contents of the files are irrelevant. I'm talking about the contents of the directories
â Philippe
Sep 13 at 12:15
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
With GNU cp
, the -T
option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.
The info documentation on this (info '(coreutils)Target directory'
) says (it's using mv
as an example):
-T
--no-target-directory
Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. This can help avoid race conditions
in programs that operate in a shared area. For example, when the
commandmv /tmp/source /tmp/dest
succeeds, there is no guarantee
that/tmp/source
was renamed to/tmp/dest
: it could have been
renamed to/tmp/dest/source
instead, if some other process
created/tmp/dest
as a directory. However, ifmv -T /tmp/source /tmp/dest
succeeds, there is no question that/tmp/source
was
renamed to/tmp/dest
.
Note that mv -T source dest
will fail if dest
is not empty.
To replace the contents of bar
with that of foo
in your example, use
rm -rf bar
cp -r foo bar
or,
rsync --archive --delete foo/ bar
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
With GNU cp
, the -T
option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.
The info documentation on this (info '(coreutils)Target directory'
) says (it's using mv
as an example):
-T
--no-target-directory
Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. This can help avoid race conditions
in programs that operate in a shared area. For example, when the
commandmv /tmp/source /tmp/dest
succeeds, there is no guarantee
that/tmp/source
was renamed to/tmp/dest
: it could have been
renamed to/tmp/dest/source
instead, if some other process
created/tmp/dest
as a directory. However, ifmv -T /tmp/source /tmp/dest
succeeds, there is no question that/tmp/source
was
renamed to/tmp/dest
.
Note that mv -T source dest
will fail if dest
is not empty.
To replace the contents of bar
with that of foo
in your example, use
rm -rf bar
cp -r foo bar
or,
rsync --archive --delete foo/ bar
add a comment |Â
up vote
1
down vote
accepted
With GNU cp
, the -T
option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.
The info documentation on this (info '(coreutils)Target directory'
) says (it's using mv
as an example):
-T
--no-target-directory
Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. This can help avoid race conditions
in programs that operate in a shared area. For example, when the
commandmv /tmp/source /tmp/dest
succeeds, there is no guarantee
that/tmp/source
was renamed to/tmp/dest
: it could have been
renamed to/tmp/dest/source
instead, if some other process
created/tmp/dest
as a directory. However, ifmv -T /tmp/source /tmp/dest
succeeds, there is no question that/tmp/source
was
renamed to/tmp/dest
.
Note that mv -T source dest
will fail if dest
is not empty.
To replace the contents of bar
with that of foo
in your example, use
rm -rf bar
cp -r foo bar
or,
rsync --archive --delete foo/ bar
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
With GNU cp
, the -T
option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.
The info documentation on this (info '(coreutils)Target directory'
) says (it's using mv
as an example):
-T
--no-target-directory
Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. This can help avoid race conditions
in programs that operate in a shared area. For example, when the
commandmv /tmp/source /tmp/dest
succeeds, there is no guarantee
that/tmp/source
was renamed to/tmp/dest
: it could have been
renamed to/tmp/dest/source
instead, if some other process
created/tmp/dest
as a directory. However, ifmv -T /tmp/source /tmp/dest
succeeds, there is no question that/tmp/source
was
renamed to/tmp/dest
.
Note that mv -T source dest
will fail if dest
is not empty.
To replace the contents of bar
with that of foo
in your example, use
rm -rf bar
cp -r foo bar
or,
rsync --archive --delete foo/ bar
With GNU cp
, the -T
option is used to ensure that the source directory will not be put inside the target directory. It will not cause to contents of the target directory to be removed.
The info documentation on this (info '(coreutils)Target directory'
) says (it's using mv
as an example):
-T
--no-target-directory
Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. This can help avoid race conditions
in programs that operate in a shared area. For example, when the
commandmv /tmp/source /tmp/dest
succeeds, there is no guarantee
that/tmp/source
was renamed to/tmp/dest
: it could have been
renamed to/tmp/dest/source
instead, if some other process
created/tmp/dest
as a directory. However, ifmv -T /tmp/source /tmp/dest
succeeds, there is no question that/tmp/source
was
renamed to/tmp/dest
.
Note that mv -T source dest
will fail if dest
is not empty.
To replace the contents of bar
with that of foo
in your example, use
rm -rf bar
cp -r foo bar
or,
rsync --archive --delete foo/ bar
answered Sep 13 at 12:18
Kusalananda
107k14209331
107k14209331
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468767%2fcp-tr-overwrite-behavior%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
What part of the manual are you referring to? Is this using GNU
cp
from coreutils, or some other implementation of thecp
command?â Kusalananda
Sep 13 at 11:48
I'm referring to
treat DEST as a normal file
. Normal files get overwritten when you copy over them. This is not the case here.â Philippe
Sep 13 at 11:58
the contents of the files are irrelevant. I'm talking about the contents of the directories
â Philippe
Sep 13 at 12:15