cp command Linux command Detailed

cp command Linux command Detailed


A, cp command Introduction

cp command is used to copy a file or directory. That is used to copy one or more source files or directory to the specified file or directory object.

Or the next directory already exists cp command to copy the source file into a single file name designated specific file.

cp command supports copying multiple files at the same time, when the copy multiple files, object files argument must be a directory that already exists, or an error.


Two, cp command syntax

cp [-options] source_file dest_file
  • source_file: source files, develop list of source files. By default, cp command can not copy the directory, unless -r / -R option.

  • dest_file: the target file, specify the destination file. When the "source" for multiple file, requires "destination file" specified directory.


Three, parameters:

  • -a: equal "dpR" parameter combination, usually reserved for links when copying directories, file properties, and copy all the contents of the directory.
  • -b: before the target file will overwrite the existing file backup target;
  • -d: Reserved symbolic links when copied.
  • -f: forced to copy a file or directory, overwrite the existing destination file without prompting.
  • -i: On the contrary, prompt before overwriting the destination file with the -f option to require the user to confirm coverage.
  • -l: do not copy the file, but generated source file hard-linked files.
  • -p: keep the source file or directory attributes when copying files.
  • -r: recursive copy directories that copy the directory and all subdirectories and files.
  • -R: with the -r option parameters.
  • -s: Creates a symbolic link, rather than copy the files on the source file;
  • -S: When backing up files with the specified suffix "SUFFIX" instead of the default file extension;
  • -u: synchronous copy the source files, copy files updated only when the source or destination file does not exist.
  • -v: Detailed display operation command execution.

Fourth, examples

1, copy the files
格式:
$ cp source_file dest_file
$ cp source_folder/*.* dest_folder
示例:
$ cp 123.tar /root/abc
$ cp *.tar /root/abc
  • cp command to copy the file to the target file, the contents of the target file with the same name will be overwritten, the contents of the target file will be destroyed.
  • cp command to copy the file to the target file, then use a different name destination file name, but the target file contents into a source file contents.
  • File path can be an absolute pathname, or a relative path name. Typically used in the current directory .or a directory ..form.
2, copy the directory
格式:
$ cp -r source_folder dest_folder
$ cp -R source_folder dest_folder
示例:
$ cp -r lsst/ /root/abc
$ cp -R lsst/ /root/abc
  • All files in the specified target directory must already exist, cp command can not create the directory.

V. Related command

1, rcp command Linux command Detailed

2, scp command Linux command Detailed

3, mv Linux command of the command Detailed

4, rcp command Linux command Detailed

Guess you like

Origin www.cnblogs.com/davidesun/p/11986668.html