Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Cp (Unix)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Shell command that copies file}} {{lowercase}} {{Infobox software | name = cp | logo = | screenshot = Cp-example-command-gimp.gif | screenshot size = | caption = Example usage of <code>cp</code> command | author = [[Bell Labs|AT&T Bell Laboratories]] | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = {{Start date and age|1971|11|03}} | latest release version = | latest release date = | programming language = Plan 9: [[C (programming language)|C]] | operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], [[KolibriOS]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3]]<br />Plan 9: [[MIT License]] | website = }} '''<code>cp</code>''' is a [[shell (computing)|shell]] [[command (computing)|command]] for copying [[computer file|files]] and [[directory (computing)|directories]]. If the [[computer user|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]],<ref name="reader">{{cite tech report |first1=M. D. |last1=McIlroy |author-link1=Doug McIlroy |year=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971β1986 |series=CSTR |number=139 |institution=Bell Labs}}</ref> and is specified by [[POSIX]]. The implementation from [[GNU]] has many additional options beyond the POSIX specification.<ref>{{cite web|url=https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html#cp-invocation|title=GNU Coreutils: cp invocation|website=GNU }}</ref> The command is bundled in [[GNU Core Utilities]]<ref>{{Cite web|url=https://linux.die.net/man/1/cp|title=Cp(1): Copy files/Directories - Linux man page}}</ref> and is available in the [[Unified Extensible Firmware Interface|EFI shell]].<ref name="EFI-Shells-and-Scripting">{{cite web | url = http://software.intel.com/en-us/articles/efi-shells-and-scripting/ | title = EFI Shells and Scripting | publisher = [[Intel]] | access-date = 2013-09-25 }}</ref> ==Options== *<code>-f</code> (force) – specifies removal of each target file if it cannot be opened for write operations; removal precedes any copying * <code>-H</code> (dereference) – follows [[symbolic link]]s so that the destination has the target file rather than a link to the target *<code>-i</code> (interactive) – prompts user to overwrite each target file that clashes with a source file *<code>-n</code> (no [[clobbering]]) – prevents overwriting files *<code>-p</code> (preserve) – preserves metadata of each source file in the destination; including: time of last modification and last access, ownership, and file permissions *<code>-R</code> or <code>-r</code> (recursive) – copy directories recursively == Modes == The command has three principal modes of operation as inferred from command-line arguments.<ref>{{Cite web | url=https://www.man7.org/linux/man-pages/man1/cp.1.html | title=Cp(1) - Linux manual page }}</ref> ===Copy file=== 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=== 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=== With the recurse command-line option, typically {{code|-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 == 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 reclusively 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 <code>cp -R clients/ customers</code> 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 == {{Wikibooks|Guide to Unix/Commands/File System Utilities#cp}} * {{Annotated link|copy (command)|copy}} * {{Annotated link|cpio}} * {{Annotated link|GNU Core Utilities}} * {{Annotated link|List of POSIX commands}} * {{Annotated link|mv (Unix)|mv}} * {{Annotated link|Rm (Unix)|rm}} * progress – Linux tool to show progress for cp, mv, dd<ref>{{Cite web|url=https://linux.die.net/man/1/progress|title=Progress(1) - Linux man page}}</ref><ref>{{Cite web|url=https://github.com/Xfennec/progress|title = Progress - Coreutils Progress Viewer|website = {{Annotated link|GitHub}}|date = 14 November 2021}}</ref> * {{Annotated link|rsync}} * {{Annotated link|Secure copy|scp}} * {{Annotated link|tar (computing)|tar}} * {{Annotated link|uUCP|uucp}} ==References== {{Reflist}} ==External links== * {{man|cu|cp}} * {{man|1|cp|FreeBSD}} * {{man|1|cp|NetBSD}} * {{man|1|cp|OpenBSD}} * {{man|1|cp|Solaris}} * {{man|1|cp|die.net}} * {{man|1|cp|Plan 9}} {{Unix commands}} {{Plan 9 commands}} {{Core Utilities commands}} [[Category:Standard Unix programs]] [[Category:Unix SUS2008 utilities]] [[Category:File copy utilities]] [[Category:Plan 9 commands]] [[Category:Inferno (operating system) commands]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Annotated link
(
edit
)
Template:Cite tech report
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Plan 9 commands
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)