Linux CP Command Direct overwrite without prompting method

Source: Internet
Author: User
Tags what parameter

In a directory where there are sometimes more copies of files, CP overrides, no matter what parameter-f or whether the hint is overwritten, this is intolerable in the CP overwrite operation.

Copy the files in the a directory to the B directory

The code is as follows Copy Code

Cp–r a/* b

When the above command is executed, every file that exists in B will prompt for coverage;

The code is as follows Copy Code

Cp–r–f a/* b

When the above command is executed, every file that exists in B is no longer prompted;


This is the ideal state we want, but sometimes it is added to-F. Some servers will default to add aliases alias cp= ' Cp-i ', when you execute CP, in fact, the implementation is cp–i.

You can see it by executing the alias at the terminal.

The code is as follows Copy Code

[Root@lamp100 ~]# Alias

Alias cp= ' Cp-i '

Can be solved like this

The code is as follows Copy Code

[Root@lamp100 ~]# VI ~/.BASHRC

Add "#" to the alias cp= ' Cp-i ' to comment out this line : wq! save exit, and then login again.

To sum up


1 Cancel the alias of CP, rest assured that it is not permanently effective

The code is as follows Copy Code

#unalias CP

#cp a/test/a

2) do not go when CP command is executed with CP

The code is as follows Copy Code

ALIAS#CP a/test/a


about the Linux CP command

CP (copy)

Function Description: Copy files or directories.

Syntax: CP [-abdfilpprrsuvx][-s < backup word tail string >][-v < Backup mode >][--help][--spares=< use time >][--version][source file or directory [ destination file or directory] [destination directory]

Supplemental Note: The CP directive is used to copy files or directories, such as specifying more than two files or directories, and the last destination is an existing directory, which copies all the files or directories previously specified to the directory. If you specify multiple files or directories at the same time, and the last destination is not an existing directory, an error message appears.

Parameter:
-A or--archive the effect of this parameter is the same as specifying the "-DPR" parameter.
-B or--backup deletes, overwriting the backup before the target file, and the backup file adds a backup string at the end of the word.
-D or--no-dereference when a symbolic connection is copied, the target file or directory is also established as a symbolic connection and points to the original file or directory that is connected to the source file or directory.
-F or--force forcibly copies a file or directory, regardless of whether the destination file or directory already exists.
-I or--interactive ask the user before overwriting the existing file.
-L or--link a hard connection to the source file, not a copy of the file.
-P or--preserve preserves the properties of the source file or directory.
-P or--parents preserves the path to the source file or directory.
-R recursively processes files in the specified directory with subdirectories.
-R or--recursive recursively processes all files in the specified directory with subdirectories.
-S or--symbolic-link a symbolic connection to the source file, not a copy of the file.
-s< Backup Word tail string > or--suffix=< backup tail string > After the target file is backed up with the "-B" parameter, the end of the backup file is added with a backup string, and the preset backup word tail string is the symbol "~".
-U or--update Use this parameter to copy the file only when the source file is changed more than the target file is updated or if the name corresponds to a target file that does not exist.
-V or--verbose displays the instruction execution procedure.
-v< Backup method > or--version-control=< backup method > Back up the destination file with the "-B" parameter, the end of the backup file is added with a backup string, which can be changed not only with the "-S" parameter, but also with "-V" parameter specifies different backup methods, a backup string is also generated at the end of a different word.  
-X or--one-file-system copied files or directories must be stored in the same file system as the CP Directive executes, otherwise they will not be replicated.
--help online Help.
--sparse=< When to save sparse files by using the timing > Settings.
--version display version information

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.