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:
- Make space before the paste (e.g.
10o<Esc>`[
), then paste. - Change the mode of the register between yank and paste:
:call setreg('', '', 'al')
- 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
Define Function in Unix/Linux Command Line (E.G. Bash)
Removing Sensitive Data from Git. "Fatal: Ambiguous Argument 'Rm'"
Convert an Iso Date to Seconds Since Epoch in Linux Bash
Is Lib{Library Name}.A/.So a Naming Convention for Static Libraries in Linux
Compiler Can't Find Libxml/Parser.H
How to Call Accept() for One Socket from Several Threads Simultaneously
-O in Linux Terminal (Dash O); What Does It Mean
Why Using Pipe for Sort (Linux Command) Is Slow
How to Use Variables with Brace Expansion
Using Bash Script to Feed Input to Command Line
How Would I Tell a Bash Script to Start Over from the Top
Where Is the Stack Memory Allocated from for a Linux Process
Assigning Dynamic Bash Variable Names Using a for Loop Seq
How to Pass Arguments with Special Characters to Call Shell Script
How to Print a Single Ascii Char
How to Paste Multi-Line Bash Codes into Terminal and Run It All at Once