ArticleDirectory
- Parameters
- Option
- Example
- Tips
Copy a file
CP [Options]Source-file destination-File
CP [Options]Source-file-list destination-directory
Parameters
Method 1:Source-File YesCPThe path name of the file to be copied;Destination-FileYesCPPath Name of the generated copy file
Method 2:Source-file-listYesCPList of file path names to be copied;Destination-FileYesCPDirectory path name of the generated copy
Option
-B. If the target file already exists, back up the target file before overwriting.
-I if the target file already exists, a prompt will be prompted during overwriting.
-F forcibly overwrite the target file, regardless of your specific permissions and prompts
-P retains the user, group, permission, modification time, and other information in the original file for copying.
-U: Compare the modification time of the original and existing target files with the same name. If the modification time of the target file is newer, the modification time is not overwritten.
-R or-r recursively copy directory layers and files
-V: displays the name of each file copied by CP.
Example CP Current Directory
$LsA.txt $CPA.txt B .txt $LsA.txt B .txt
Copy a.txt to B .txt in the current directory.
CP-IV Current Directory
$LsA.txt B .txt $CP-IV a.txt B .txtCP: Overwrite?"B .txt"? Y"A.txt"->"B .txt"
Copy in the current directory. If the file already exists, check whether it is overwritten and display the copy information.
CP multiple file directories
$CPA.txt B .txt c.txt ABC/$LsABC a.txt B .txt c.txt $LsABC/A.txt B .txt c.txt
Copy multiple files to a directory. Copy a.txt B .txt c.txt to the ABC folder in the same directory.
CP-R
$CP-R ABCDir/$LsABC a.txt B .txt c.txtDir$Ls DirA.txt B .txt c.txt
Recursively copy the entire directory, including the directory structure and file
Tips
The CP option also involves copying linked files, which are not listed here, and I am not rewriting the manual