cp

Command Function

This command is used to create a copy for a file.

Syntax

cp [SOURCEFILE] [DESTFILE]

Parameters

Table 1 Parameter description

Parameter

Description

Value Range

--help

Displays help information.

N/A

SOURCEFILE

Specifies the path of the source file.

This command does not support copy of a directory, but supports copy of multiple files at a time.

DESTFILE

Specifies the destination file path.

Both a directory and a file are supported.

Usage

  • The name of the source file cannot be the same as that of the destination file in the same path.
  • SOURCEFILE must exist and cannot be a directory.
  • SOURCEFILE supports wildcard characters * and ?. The asterisk (*) indicates any number of characters, and the question mark (?) represents a single character. DESTFILE does not support wildcard characters. If SOURCEFILE specifies multiple files, DESTFILE must be a directory.
  • If DESTFILE specifies a directory, this directory must exist. In this case, the destination file is named after the source file.
  • If DESTFILE specifies a file, the directory for this file must exist. In this case, the file copy is renamed.
  • If the destination file does not exist, a new file is created. If the destination file already exists, the existing file is overwritten.

NOTICE: When important system resources are copied, unexpected results such as a system breakdown may occur. For example, when the /dev/uartdev-1 file is copied, the system may stop responding.

Example

Run cp hello-OHOS.txt hello-harmony.txt ./tmp/.

Output

Copying hello-OHOS.txt and hello-harmony.txt to /tmp/:

OHOS:/$ ls
bin  hello-OHOS.txt     proc     system    vendor
dev  hello-harmony.txt  sdcard   userdata
etc  lib                storage  usr
OHOS:/$ mkdir tmp
OHOS:/$ cp hello-OHOS.txt hello-harmony.txt tmp/
OHOS:/$ ll tmp
total 0
-rwxrwxrwx 1 0 0 0 1979-12-31 00:00 hello-OHOS.txt*
-rwxrwxrwx 1 0 0 0 1979-12-31 00:00 hello-harmony.txt*