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
Force cp to overwrite when -i option used by defaul
You have two possibilities:
First uses system cp instead of invoking your alias:
/bin/cp .....
Second overrides -i option (so it looks like cp -i -n instead)
cp -n ....
The second one is much less readable so I suggest using the first one.
is there any way to force copy? copy without overwrite prompt, using windows?
You're looking for the /Y
switch.
How to specify the files to overwrite using linux cp command on PHP?
Can you not call copy with only those files that need to be overwritten and exclude the files which are not to be copied?
By default cp overwrites the file, you can try the -f (force option) but that should bot be necessary.
XCOPY: Overwrite all without prompt in BATCH
The solution is the /Y
switch:
xcopy "C:\Users\ADMIN\Desktop\*.*" "D:\Backup\" /K /D /H /Y
How to remove double quotes without escape (^) in cmd/ batchfile?
This should work:
for /f %a in ("%username%") do echo %a
output:
jhon^smith
(btw: It should be spelt john^smith
but never mind.)
Explanation:
In the command echo %username%
, cmd.exe
replaces %username%
with its actual content, so the command becomes echo jhon^smith
. This is then parsed, the the ^
is processed as the escape character, so it replaces ^s
with s
.
In the command for /f %a in ("%username%") do echo %a
, the quoted string is treated as a string without the quotes, and no parsing of ^
is performed. Type for /?
for more details.
Related Topics
How to Send a Sequence of at Commands to a Serial Port in Bash
Install Marklogic Centos Virtualbox Vm
Why Does the Wc Command Count One More Character Than Expected
Execute Script as Another User Whilst Not Being Root
Mercurial Hg No Changes Found - Can't Hg Push Out
Trying to Ping Linux Vm Hosted on Azure Does Not Work
How to Set Up Curl to Permanently Use a Proxy
Execute a Shell Script Everyday at Specific Time
Dump Conf from Running Nginx Process
How to Get Cmake to Use the Default Compiler on System Path
Is There a Special Restriction on Commands Executed by Cron
Overwrite Input File Using Awk
How to Tell Qt to Use Different Openssl