Is there a way to check whether `cp -r` would overwrite anything?
Is there a way to check if cp -r
would overwrite anything, without actually copying anything?
-n
seems to copy files that don't collide, which is not what I want.
bash cp
add a comment |
Is there a way to check if cp -r
would overwrite anything, without actually copying anything?
-n
seems to copy files that don't collide, which is not what I want.
bash cp
Possible duplicate of Linux how to copy but not overwrite?
– l'L'l
Jan 1 at 18:13
Cross-site duplicate: unix.stackexchange.com/questions/187937/…
– tripleee
Jan 2 at 5:12
add a comment |
Is there a way to check if cp -r
would overwrite anything, without actually copying anything?
-n
seems to copy files that don't collide, which is not what I want.
bash cp
Is there a way to check if cp -r
would overwrite anything, without actually copying anything?
-n
seems to copy files that don't collide, which is not what I want.
bash cp
bash cp
edited Jan 2 at 10:43
common sense
2,57351625
2,57351625
asked Jan 1 at 17:59
Filip HaglundFilip Haglund
7,10064281
7,10064281
Possible duplicate of Linux how to copy but not overwrite?
– l'L'l
Jan 1 at 18:13
Cross-site duplicate: unix.stackexchange.com/questions/187937/…
– tripleee
Jan 2 at 5:12
add a comment |
Possible duplicate of Linux how to copy but not overwrite?
– l'L'l
Jan 1 at 18:13
Cross-site duplicate: unix.stackexchange.com/questions/187937/…
– tripleee
Jan 2 at 5:12
Possible duplicate of Linux how to copy but not overwrite?
– l'L'l
Jan 1 at 18:13
Possible duplicate of Linux how to copy but not overwrite?
– l'L'l
Jan 1 at 18:13
Cross-site duplicate: unix.stackexchange.com/questions/187937/…
– tripleee
Jan 2 at 5:12
Cross-site duplicate: unix.stackexchange.com/questions/187937/…
– tripleee
Jan 2 at 5:12
add a comment |
3 Answers
3
active
oldest
votes
The easiest way is to use the rsync
command there you have a lot of parameters to override the target or delete files on the target if you want.
https://linux.die.net/man/1/rsync
or like mentioned in the comments you could use cp -n
for --no-clobber
. But in general i would suggest rsync there you have a lot more possibilities.
Agree. If you need to know, cp is not the right tool.
– Thorbjørn Ravn Andersen
Jan 1 at 18:03
1
Note that cp has the -i --interactive option and the -n, --no-clobber option.
– Roadowl
Jan 1 at 18:11
add a comment |
cp has the -i --interactive option and the -n, --no-clobber option.
See `man 1 cp'.
add a comment |
To only check if the file exists in the target location, but not actually perform any copying you can use the diff
command with the -r
option.
From man diff
:
-r, --recursive
recursively compare any subdirectories found
diff -r --brief --report-identical-files /source-folder/ /target-folder/ | grep -v '^Only in'
--brief
is listing files that differ (same as-q
)
--report-identical-files
does the same for files that don't differ (same as-s
)- The
grep -v '^Only in'
removes files that are only in one directory tree, because those will not be overwritten.
The output will look something like this:
Files /source-folder/file1.txt and /target-folder/file1.txt are identical
Files /source-folder/file2.jpg and /target-folder/file2.jpg differ
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997692%2fis-there-a-way-to-check-whether-cp-r-would-overwrite-anything%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The easiest way is to use the rsync
command there you have a lot of parameters to override the target or delete files on the target if you want.
https://linux.die.net/man/1/rsync
or like mentioned in the comments you could use cp -n
for --no-clobber
. But in general i would suggest rsync there you have a lot more possibilities.
Agree. If you need to know, cp is not the right tool.
– Thorbjørn Ravn Andersen
Jan 1 at 18:03
1
Note that cp has the -i --interactive option and the -n, --no-clobber option.
– Roadowl
Jan 1 at 18:11
add a comment |
The easiest way is to use the rsync
command there you have a lot of parameters to override the target or delete files on the target if you want.
https://linux.die.net/man/1/rsync
or like mentioned in the comments you could use cp -n
for --no-clobber
. But in general i would suggest rsync there you have a lot more possibilities.
Agree. If you need to know, cp is not the right tool.
– Thorbjørn Ravn Andersen
Jan 1 at 18:03
1
Note that cp has the -i --interactive option and the -n, --no-clobber option.
– Roadowl
Jan 1 at 18:11
add a comment |
The easiest way is to use the rsync
command there you have a lot of parameters to override the target or delete files on the target if you want.
https://linux.die.net/man/1/rsync
or like mentioned in the comments you could use cp -n
for --no-clobber
. But in general i would suggest rsync there you have a lot more possibilities.
The easiest way is to use the rsync
command there you have a lot of parameters to override the target or delete files on the target if you want.
https://linux.die.net/man/1/rsync
or like mentioned in the comments you could use cp -n
for --no-clobber
. But in general i would suggest rsync there you have a lot more possibilities.
edited Jan 1 at 18:15
answered Jan 1 at 18:02
René HöhleRené Höhle
20.4k135366
20.4k135366
Agree. If you need to know, cp is not the right tool.
– Thorbjørn Ravn Andersen
Jan 1 at 18:03
1
Note that cp has the -i --interactive option and the -n, --no-clobber option.
– Roadowl
Jan 1 at 18:11
add a comment |
Agree. If you need to know, cp is not the right tool.
– Thorbjørn Ravn Andersen
Jan 1 at 18:03
1
Note that cp has the -i --interactive option and the -n, --no-clobber option.
– Roadowl
Jan 1 at 18:11
Agree. If you need to know, cp is not the right tool.
– Thorbjørn Ravn Andersen
Jan 1 at 18:03
Agree. If you need to know, cp is not the right tool.
– Thorbjørn Ravn Andersen
Jan 1 at 18:03
1
1
Note that cp has the -i --interactive option and the -n, --no-clobber option.
– Roadowl
Jan 1 at 18:11
Note that cp has the -i --interactive option and the -n, --no-clobber option.
– Roadowl
Jan 1 at 18:11
add a comment |
cp has the -i --interactive option and the -n, --no-clobber option.
See `man 1 cp'.
add a comment |
cp has the -i --interactive option and the -n, --no-clobber option.
See `man 1 cp'.
add a comment |
cp has the -i --interactive option and the -n, --no-clobber option.
See `man 1 cp'.
cp has the -i --interactive option and the -n, --no-clobber option.
See `man 1 cp'.
answered Jan 1 at 18:13
RoadowlRoadowl
128310
128310
add a comment |
add a comment |
To only check if the file exists in the target location, but not actually perform any copying you can use the diff
command with the -r
option.
From man diff
:
-r, --recursive
recursively compare any subdirectories found
diff -r --brief --report-identical-files /source-folder/ /target-folder/ | grep -v '^Only in'
--brief
is listing files that differ (same as-q
)
--report-identical-files
does the same for files that don't differ (same as-s
)- The
grep -v '^Only in'
removes files that are only in one directory tree, because those will not be overwritten.
The output will look something like this:
Files /source-folder/file1.txt and /target-folder/file1.txt are identical
Files /source-folder/file2.jpg and /target-folder/file2.jpg differ
add a comment |
To only check if the file exists in the target location, but not actually perform any copying you can use the diff
command with the -r
option.
From man diff
:
-r, --recursive
recursively compare any subdirectories found
diff -r --brief --report-identical-files /source-folder/ /target-folder/ | grep -v '^Only in'
--brief
is listing files that differ (same as-q
)
--report-identical-files
does the same for files that don't differ (same as-s
)- The
grep -v '^Only in'
removes files that are only in one directory tree, because those will not be overwritten.
The output will look something like this:
Files /source-folder/file1.txt and /target-folder/file1.txt are identical
Files /source-folder/file2.jpg and /target-folder/file2.jpg differ
add a comment |
To only check if the file exists in the target location, but not actually perform any copying you can use the diff
command with the -r
option.
From man diff
:
-r, --recursive
recursively compare any subdirectories found
diff -r --brief --report-identical-files /source-folder/ /target-folder/ | grep -v '^Only in'
--brief
is listing files that differ (same as-q
)
--report-identical-files
does the same for files that don't differ (same as-s
)- The
grep -v '^Only in'
removes files that are only in one directory tree, because those will not be overwritten.
The output will look something like this:
Files /source-folder/file1.txt and /target-folder/file1.txt are identical
Files /source-folder/file2.jpg and /target-folder/file2.jpg differ
To only check if the file exists in the target location, but not actually perform any copying you can use the diff
command with the -r
option.
From man diff
:
-r, --recursive
recursively compare any subdirectories found
diff -r --brief --report-identical-files /source-folder/ /target-folder/ | grep -v '^Only in'
--brief
is listing files that differ (same as-q
)
--report-identical-files
does the same for files that don't differ (same as-s
)- The
grep -v '^Only in'
removes files that are only in one directory tree, because those will not be overwritten.
The output will look something like this:
Files /source-folder/file1.txt and /target-folder/file1.txt are identical
Files /source-folder/file2.jpg and /target-folder/file2.jpg differ
answered Jan 2 at 11:09
Samuel KirschnerSamuel Kirschner
9351717
9351717
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997692%2fis-there-a-way-to-check-whether-cp-r-would-overwrite-anything%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Linux how to copy but not overwrite?
– l'L'l
Jan 1 at 18:13
Cross-site duplicate: unix.stackexchange.com/questions/187937/…
– tripleee
Jan 2 at 5:12