How to copy a CP file without prompting direct Overwriting

Source: Internet
Author: User
Tags what parameter

During CP overwriting in RedHat, No matter what parameter-F is added or whether the request is overwritten or not, this is intolerable when writing scripts or a large number of CP overwriting operations...

Try to explain this problem
Create an experiment environment:

[Root @ devdb ~] # Mkdir-P testing/1111
[Root @ devdb ~] # Mkdir-P testing/2222
[Root @ devdb ~] # Touch test/1111/aaa.txt

The directory structure is as follows:

[Root @ devdb ~] # Ls-r test/
Test /:
1111 2222
 
Testing/1111:
Aaa.txt

[Note] There are two folders 1111,2222 under test. There is a aaa.txt in 1111. now we need to copy the aaa.txt file to 2222.

The first copy is successful because there is no file in the 2222 folder.

[Root @ devdb ~] # Cp-r test/1111/aaa.txt test/2222/

Run this command again, and the prompt is:

[Root @ devdb ~] # Cp-r test/1111/aaa.txt test/2222/
CP: overwrite 'test/2222/aaa.txt '?

This is because there is an aaa.txt under 2222. let's take a look:

[Root @ devdb ~] # Ls-r test/
Test /:
1111 2222
 
Testing/1111:
Aaa.txt
 
Testing/2222:
Aaa.txt

If a large number of files already exist and must be overwritten, what should I do without prompting me?

[Root @ devdb ~] # Cp-r-F test/1111/aaa.txt test/2222/
CP: overwrite 'test/2222/aaa.txt '?

Adding-F does not work either...

This is because RedHat creates an alias for CP:

[Root @ devdb ~] # Alias
Alias CP = 'cp-I'
Alias L. = 'LS-D. * -- color = tty'
Alias LL = 'LS-l -- color = tty'
Alias ls = 'ls -- color = tty'
Alias mv = 'mv-I'
Alias Rm = 'rm-I'
Alias Vi = 'vim'
Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde'

When you execute CP, the actual execution is CP-I

 

Yes

[Root @ devdb ~] # Vi ~ /. Bashrc

Add "#" before alias CP = 'cp-I 'to comment out this line: WQ! Save launch

#. Bashrc
 
# User specific aliases and functions
 
Alias Rm = 'rm-I'
# Alias CP = 'cp-I'
Alias mv = 'mv-I'
 
# Source Global definitions
If [-F/etc/bashrc]; then
./Etc/bashrc
Fi

Valid after Logon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.