cp
Original authorAT&T Bell Laboratories
DevelopersVarious open-source and commercial developers
ReleaseNovember 3, 1971; 54 years ago (1971-11-03)
Written inPlan 9: C
Operating systemUnix, Unix-like, Plan 9, Inferno, KolibriOS
PlatformCross-platform
TypeCommand
Licensecoreutils: GPLv3
Plan 9: MIT License

cp is a shell command for copying files and directories.

If the user has write access to a target file, the command copies the content by opening it in update mode. This preserves the file's inode instead of creating a new file with default permissions.

The command was part of Version 1 Unix,[1] and is specified by POSIX. The implementation from GNU has many additional options beyond the POSIX specification.[2] The command is bundled in GNU Core Utilities[3] and is available in the EFI shell.[4]

Options

edit
  • -f (force) – specifies removal of each target file if it cannot be opened for write operations; removal precedes any copying
  • -H (dereference) – follows symbolic links so that the destination has the target file rather than a link to the target
  • -i (interactive) – prompts user to overwrite each target file that clashes with a source file
  • -n (no clobbering) – prevents overwriting files
  • -p (preserve) – preserves metadata of each source file in the destination, including the time of last modification and last access, ownership, and file permissions
  • -R or -r (recursive) – copy directories recursively

Modes

edit

The command has three principal modes of operation as inferred from command-line arguments.[5]

Copy file

edit

For a path to an existing file followed by a path that does not refer to an existing directory, the file at the first path is copied to the second path.

cp [-fHip][--] sourcefile targetfile

Copy files to directory

edit

For one or more paths to existing files followed by a path to an existing directory, the files are copied to the directory.

cp [-fHip] [--] sourcefile... targetdirectory

Copy directory

edit

With the recurse command-line option, typically -r, a path to an existing directory and a second path, the files of the directory are copied to the second path. If the second path refers to nothing, the source directory is copied to that path. If the second path refers to an existing directory, the source directory is copied into the destination directory as a subdirectory.

cp -r|-R [-fHip] [--] sourcedirectory... targetdirectory

Examples

edit

This copies file prog.c to file prog.bak. If prog.bak does not already exist, this creates it. If it does exist, its content will be replaced.

cp prog.c prog.bak

This copies the files jones and smith into the pre-existing directory clients.

cp jones smith clients

This copies file smith to a file named smith.jr. Instead of creating a file with the current date and time stamp, the command copies the date and time from the original. The copy also receives other metadata from the original including access control protection.

cp -p smith smith.jr

This recursively copies the directory clients, including its files, subdirectories, and the files in those subdirectories, to a new directory customers/clients.

cp -R clients customers

Some implementations behave differently in recursive mode, depending on the termination of the directory path. Using cp -R clients/ customers in the GNU implementation behaves as above. However, with a BSD implementation, it copies the contents of the clients directory, instead of the directory clients itself. The same happens in both GNU and BSD implementations if the path of the source directory ends in . or .. (with or without trailing slash).

See also

edit
  • copy – Shell command for copying files
  • cpio – File archiver and associated file format
  • GNU Core Utilities – Collection of standard, Unix-based utilities from GNU
  • List of POSIX commands
  • mv – Shell command for moving files
  • rm – Shell command for deleting files
  • progress – Linux tool to show progress for cp, mv, dd[6][7]
  • rsync – File synchronization protocol and software
  • scp – Network protocol for copying files between computers
  • tar – File format and file archiver program
  • uucp – Suite of computer programs and protocols

References

edit
  1. ^ McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139.
  2. ^ "GNU Coreutils: cp invocation". GNU. Archived from the original on 2022-01-26. Retrieved 2015-03-17.
  3. ^ "Cp(1): Copy files/Directories - Linux man page". Archived from the original on 2022-01-30. Retrieved 2019-01-19.
  4. ^ "EFI Shells and Scripting". Intel. Archived from the original on 2013-09-27. Retrieved 2013-09-25.
  5. ^ "Cp(1) - Linux manual page". Archived from the original on 2022-01-29. Retrieved 2022-02-13.
  6. ^ "Progress(1) - Linux man page". Archived from the original on 2019-11-06. Retrieved 2019-11-06.
  7. ^ "Progress - Coreutils Progress Viewer". GitHub – Software development collaboration platform. 14 November 2021.
edit

📚 Artikel Terkait di Wikipedia

TYPE (DOS command)

TYPE command. It is also available in the open source MS-DOS emulator DOSBox and the EFI shell. In Windows PowerShell, type is a predefined command alias

Help (command)

EFI shell. On Unix, the command is part of the Source Code Control System and prints help information for the SCCS commands. The Multics help command

Alias (command)

PowerShell, ReactOS, EFI shell, and IBM i. Aliasing functionality in MS-DOS and Command Prompt is provided by the DOSKEY command. Since aliases are defined

System time

D. Brown (2000). "Int 0x1A, AH=0x04". Ralf Brown's Interrupt List. "CP/M Plus (CP/M Version 3.0) Operating System Guide" (PDF). "BDOS system calls". Ralf

Rm (Unix)

EFI shell. and Windows (via UnxUtils). The del command provides a similar capability in MS-DOS, OS/2, and Command Prompt. Like rm, the unlink command

UEFI

version of shell. The following is a list of commands supported by the EFI shell. alias attrib bcfg cd cls comp cp date dblk dh dmpstore echo Edd30 EddDebug

List of command-line interpreters

Command Language (OpenVMS, various PDP-11 O/Ses...) DOS Wedge – (Commodore 64) EFI-SHELL Microsoft BASIC Singularity (operating system) SymShell Tandem Application

Fat binary

that contained both 32-bit and 64-bit EFI binaries. CP/M-80, MP/M-80, Concurrent CP/M, CP/M Plus, Personal CP/M-80, SCP and MSX-DOS executables for the