LINUX CP Command Usage Example

  

The Linux cp command copy command is very useful. The cp command can copy files (directories) in the specified path to another file or directory, which is equivalent to the COPY and XCOPY commands under DOS. The cp command syntax is as follows: cp [options] <source file or directory> <target file or directory> or cp [options] source1 source2 source3 …. The first command in the directory is a single file or directory copy, the next one is Copy multiple files to the last directory. Options options include: ■- a Retain link and file attributes, recursive copy directory, equivalent to the following three combinations of d, p, r options. ■- d Keep the link when copying. ■- f Delete the existing target file without prompting. ■- i A confirmation prompt will be given before the target file is overwritten, which is an interactive copy. ■- p After copying the contents of the source file, it will also copy its modification time and access rights to the new file. ■- r If the source file is a directory file, cp will recursively copy all subdirectories and files in that directory. Of course, the target file must be a directory name. ■- l No copy, just a link file. ■-s is copied into a symbolic link (symbolic link), which is a "shortcut" file; ■-u updates destination if destination is older than source. Example of using the cp command: 1. Copy the file file1 to file2. After copying, the name is changed to file2cp -i file1 file2 or cp file1 file22. Copy the file file1 to the dir1 directory. After copying, the name is still not file1cp -i file1 dir1 or , cp file1 dir13, copy the directory dir1 to the dir2 directory, the replication result directory is renamed to dir2cp -r dir1 dir24, all files in the directory dir1 include folders, all copied to the dir2 directory cp -r dir1/*.* Common error of dir2: 1. Prompt cp: omitting directory error When copying directory, use -r option to recursively copy, as follows: cp -r dir1 dir2

Copyright © Windows knowledge All Rights Reserved