Linux How to Copy But Not Overwrite

Linux how to copy but not overwrite?

Taken from the man page:

-n, --no-clobber
do not overwrite an existing file (overrides a previous -i option)

Example:

cp -n myoldfile.txt mycopiedfile.txt

How to force cp to overwrite without confirmation

You can do yes | cp -rf xxx yyy, but my gutfeeling says that if you do it as root - your .bashrc or .profile has an alias of cp to cp -i, most modern systems (primarily RH-derivatives) do that to root profiles.

You can check existing aliases by running alias at the command prompt, or which cp to check aliases only for cp.

If you do have an alias defined, running unalias cp will abolish that for the current session, otherwise you can just remove it from your shell profile.

You can temporarily bypass an alias and use the non-aliased version of a command by prefixing it with \, e.g. \cp whatever

How do I block copy into the original text not overwrite in VI?

If you've yanked a blockwise visual selection, pasting that will insert the block at the current position, into the existing text, without adding new lines or shifting existing text downwards. That's the expected behavior; you're effectively handling a square "cutout" of text, separate from the underlying text structure.

If you're handling complete line(s) (and based on your screenshot, you're doing just that), the correct approach is to select and yank the text linewise; i.e. use Shift + V instead of Ctrl + V for the selection (or [count]yy in normal mode, which is faster if you know the number of lines).

If you really need to yank a square block, and paste this as new lines, there are the following approaches:

  1. Make space before the paste (e.g. 10o<Esc>`[), then paste.
  2. Change the mode of the register between yank and paste: :call setreg('', '', 'al')
  3. Use my UnconditionalPaste plugin; it offers (among others) a glp command that forces linewise pasting, regardless of how the text was yanked.

Overwrite file in copying IF content to of them not the same

Have you tried the command line:

cp -ru A/* B/

Should copy recursively all changed files (more recent timestamp) from directory A to directory B.

You can also use -a instead of -r in the command line, depending on what you want to do. See the cp man page.

Copy files without overwrite

For %F In ("C:\From\*.*") Do If Not Exist "C:\To\%~nxF" Copy "%F" "C:\To\%~nxF"


Related Topics



Leave a reply



Submit