Hubbry Logo
Copy (command)Copy (command)Main
Open search
Copy (command)
Community hub
Copy (command)
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contribute something
Copy (command)
Copy (command)
from Wikipedia

copy
DevelopersDEC, Intel, MetaComCo, Heath Company, Zilog, Microware, HP, Microsoft, IBM, DR, TSL, Datalight, Novell, Toshiba
Operating systemRT-11, OS/8, RSX-11, ISIS-II, iRMX 86, TOPS-10, TOPS-20, OpenVMS, TRIPOS, HDOS, DOS, MSX-DOS, FlexOS, 4680 OS, 4690 OS, PC-MOS, Z80-RIO, OS-9, MPE/iX, OS/2, Windows, ReactOS, SymbOS, DexOS
TypeCommand
LicenseHDOS: PD
MS-DOS: MIT
PC-MOS: GPL v3
ReactOS: GPL v2

copy is a shell command for copying files.[1][2]

Different implementations provide various capabilities, such as:

  • Combining (concatenating) multiple files into a single file
  • If multiple source files are specified before the path to an existing directory, then files are copied to the directory
  • Support for text vs. binary data; for text, the command stops when it reaches an end-of-file (EOF) character; for binary, files are copied in their entirety; ignoring EOF
  • In DOS, a file can be copied to or from a device. For example, copy path con outputs the file at path to the console, and copy con path copies text typed at the console to a file at path

Implementations

[edit]

The command is available in RT-11,[3] OS/8,[4] RSX-11,[5] ISIS-II,[6] iRMX 86,[7] TOPS-10,[8] TOPS-20,[9] OpenVMS,[10] MetaComCo TRIPOS,[11] HDOS,[12] Z80-RIO,[13] OS-9,[14] DOS, FlexOS,[15] 4690 OS,[16] PC-MOS,[17] HP MPE/iX,[18] OS/2,[19] Windows,[20] ROM-DOS,[21] ReactOS,[22] SymbOS, DexOS, and 86-DOS.[23]

Under IBM PC DOS/MS-DOS the command is available since version 1.[24]

Some shells provide a copy command with a different name. In Unix-based systems, the copy command is cp. In CP/M, the command is PIP. in OpenVOS, the command is copy_file.[25]

DOS

[edit]

The following copies existing file fromfile to path tofile.

copy fromfile tofile

A file can be copied to a device. The following sends a file to the printer on lpt1.

copy letter.txt lpt1

The following outputs to stdout, like the type command.

copy letter.txt con

The following concatenates the page# files into book.txt – like cat.

copy page1.txt+page2.txt book.txt 

The command can copy files between drives.

The following uses text mode to copy text of the file; stopping when it reaches an EOF character.

copy /a doc1.txt + doc2.txt doc3.txt
copy /a *.txt doc3.txt

The following uses binary mode; concatenating files in their entirety; ignoring EOF characters.

copy /b image1.jpg + image2.jpg image3.jpg

See also

[edit]
  • XCOPY – Shell command for copying files

References

[edit]

Further reading

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
The copy command is a built-in command-line in Windows and operating systems that copies one or more files from a specified source location to a destination location, supporting both single files and file concatenation using the + operator. It treats files as either ASCII text (for line-ending conversions) or binary (preserving exact contents) by default and can verify copied . Unlike more advanced tools like xcopy or robocopy, which handle directories and subdirectories, copy is primarily designed for individual files or simple batches and does not create directories. Introduced with version 1.0 in 1981, the copy command has been an internal component of all subsequent operating systems, including through , with minor syntax enhancements over time such as the addition of restartable network copying in later versions. It originated as a fundamental file management tool in the environment to facilitate basic data duplication without graphical interfaces. In the Windows Recovery Environment, it serves a similar role for and repair tasks. The basic syntax is copy [options] <source> [+ <source> [...]] <destination>, where options include /v for verification, /y to suppress overwrite prompts, /z for restartable copies over networks, and /a or /b to specify ASCII or binary mode. For example, copy file1.txt + file2.txt output.txt concatenates two text files into one, while copy *.txt c:\backup\ copies all .txt files to a directory. Parameters like /d allow decryption of encrypted files during copying, ensuring compatibility with modern Windows security features.

Overview

Purpose and Functionality

The copy command is a command-line utility in MS-DOS and Microsoft Windows operating systems, designed to create duplicate copies of files from one location to another. It operates by reading the contents of the source and writing them to a target destination, ensuring the original files remain unchanged while producing independent replicas. This process supports efficient data replication without altering the source, making it a core component of file system manipulation in text-based environments. In terms of mechanics, the command duplicates file contents byte-for-byte and preserves associated metadata such as timestamps. It is limited to copying individual files and does not support recursive traversal or replication of directories or subdirectories; for that, advanced tools like xcopy or robocopy are used. The primary use cases for the copy command encompass backup operations to safeguard data against loss, data migration between storage devices or systems, and routine file management tasks like organizing or distributing content in shell-based workflows. These applications highlight its role in enabling reliable, automated file handling without reliance on graphical interfaces. It often functions as a backend mechanism underlying copy operations in graphical file managers. Introduced as a fundamental tool in version 1.0 in 1981, the copy command exemplifies simplicity and ubiquity in facilitating text-based interactions with operating systems. Its enduring presence underscores the value of straightforward utilities for essential file operations across diverse computing environments.

Relation to Similar Commands

The copy command in DOS-based systems functions as a direct analog to the cp command in operating systems, with both utilities designed to duplicate files or directories from a source to a destination while preserving the original. A key distinction lies in their naming conventions: DOS employs the explicit term "copy," reflecting its origins in simpler, English-word-based command interfaces, whereas Unix abbreviates it to "cp" as part of a broader of terse, two-letter command names for in early terminal environments. These parallel developments in the 1970s and 1980s—Unix from and DOS from —resulted in functionally similar tools but with shaped by independent design philosophies, where Unix prioritized brevity and DOS favored readability for non-expert users. In contrast to relocation commands like move in DOS or mv in Unix, the copy command creates an independent duplicate without altering or removing the source file, ensuring data redundancy during operations. The move and mv commands, by comparison, transfer files by renaming paths or changing locations, effectively deleting the original after successful placement, which can lead to data loss if interrupted. This duplication versus relocation paradigm makes copy particularly useful for backup scenarios or when verifying transfers before committing changes. Similarly, the copy command differs from renaming utilities such as ren (or rename) in DOS and mv in Unix (when used solely for renaming within the same volume), as it involves content replication rather than mere metadata alteration. Renaming commands modify only the file's name or directory entry without generating a new data copy, thus avoiding the storage overhead and potential for version conflicts associated with duplication. In DOS, ren explicitly cannot move files across drives, reinforcing its focus on in-place renaming, while copy enables cross-volume duplication. Across various systems, the copy command often serves as a safer alternative to move equivalents, as it retains the source file intact during transfers, mitigating risks from power failures, network issues, or errors that could otherwise result in lost data—effectively combining duplication with optional manual deletion for controlled operations. In scripting contexts, copy integrates with move and rename to form robust file management workflows, such as staging duplicates before relocation.

Syntax and Usage

General Syntax

The general syntax of the copy command follows the structure copy [options] source destination, where source denotes the input file, files, or path to be duplicated, and destination specifies the target location or filename for the resulting copy. This form provides the foundational template for invoking the command in command-line environments, ensuring the transfer of file contents from the specified source to the designated output. For batch operations, the syntax accommodates multiple sources by allowing a list of input files or paths followed by a single destination, typically a directory, to replicate several items in one execution. This enables efficient handling of grouped file transfers without requiring separate invocations for each item. Path specifications within the command adhere to standard conventions, supporting both relative paths (relative to the current ) and absolute paths (from the ) for precise targeting. Wildcard characters, such as the (*) for matching any characters in a and the (?) for single-character substitution, are permitted in source arguments to select multiple files matching a pattern. A distinctive feature is file , where multiple source files can be combined into a single destination file using the + operator, such as copy file1.txt + file2.txt combined.txt. This is particularly useful for text files in ASCII mode.

Key Options and Flags

The copy command provides several optional flags that modify its core behavior, allowing users to control aspects such as verification, overwrite handling, and file type treatment. These flags are generally optional, with the command's defaults designed to favor non-destructive operations, such as prompting before overwriting existing files to prevent accidental . Key options include /v to verify that files are written correctly to the destination, ensuring ; /y to suppress prompts for overwriting existing files, and /-y to enable them. The /z flag enables restartable for networked files, allowing interrupted transfers to resume. For file type specification, /a treats the file as ASCII text (performing line-ending conversions), while /b treats it as binary (preserving exact contents); these can apply to source, destination, or both. Additional flags are /d to decrypt encrypted files during , and /n to use short (8.3) filenames if long names cause issues. The command does not support recursive copying of directories or subdirectories; for such operations, use tools like xcopy.

History

Origins in Early Systems

The roots of the copy command trace back to file utilities developed in the Multics operating system during the late 1960s, where specialized modules enabled the duplication of file contents to alternative media such as tapes or printers, supporting efficient data management in a multi-user time-sharing environment. These utilities influenced the design of early Unix file operations, as key developers like Ken Thompson had participated in the Multics project at Bell Labs and sought to retain its interactive, communal computing model on more modest hardware. The motivation stemmed from the need for straightforward file duplication in resource-constrained, multi-user systems lacking graphical interfaces, allowing users to share and manipulate files via command-line tools without disrupting ongoing processes. In 1971, formalized the copy functionality in the first edition of Unix, released on November 3 as part of the Unix Programmer's Manual, where it appeared as the cp command for basic file copying from source to destination. This initial implementation, part of over 60 core utilities, focused solely on essential source-to-destination copying without advanced flags for preservation of attributes or recursive handling, reflecting the system's emphasis on simplicity and efficiency for a PDP-11 . Early suggestions, such as McIlroy's proposal for an "inputfile copy outputfile" syntax, evolved into the concise cp x y form to streamline file operations in a multi-programmer setting. The command's core behavior was later standardized in POSIX.1-1988, which defined its fundamental role in systems by specifying file copying semantics, including handling of permissions and error conditions, to promote portability across multi-user operating environments. This formalization built on the original Unix design, ensuring consistent duplication of files and basic hierarchies while maintaining compatibility with early implementations.

Development in DOS

The copy command was introduced as an internal component of the shell in 1.0, released on August 12, 1981, to facilitate file and device copying on PC-compatible systems. This early implementation supported basic syntax for single-file transfers, such as COPY source destination, and was designed to operate within the constraints of the file system, which enforced an convention limiting names to eight characters plus a three-character extension. Drawing inspiration from , the predominant operating system for 8-bit microcomputers at the time, 's copy command adapted concepts from CP/M's Peripheral Interchange Program (PIP), which handled similar tasks but used a more cryptic syntax. Unlike Unix's concise cp utility, the version employed the full word "copy" to align with the shell's emphasis on straightforward, English-based commands suitable for business and non-programmer users in the emerging personal computing market. From version 1.0, it included wildcard support (* and ?) for batch operations, such as COPY *.TXT A:, and the ability to concatenate files using the + operator, like COPY file1.txt + file2.txt combined.txt, which proved essential for managing limited storage on 160 KB floppy disks prevalent in the era. The command also featured the /A from its debut, enabling ASCII mode to treat files as text and halt copying at Ctrl+Z markers, contrasting with binary mode (default or via /B) for executables like .COM and .EXE files. This distinction was critical in the environment, where concatenation in binary mode allowed users to merge program segments or overlays into single files to fit within disk capacity limits, optimizing space for self-loading executables. The command's functionality remained largely stable through subsequent releases, with minor refinements for reliability on larger storage media while preserving . In later versions like 6.0 (1993), additional options such as /L for linking files were introduced, reflecting evolving capabilities without altering core syntax.

Implementations

Unix-like Systems

In systems, the cp command serves as the primary utility for copying files and directories, implemented as /bin/cp and designed to comply with the standard, which defines its core syntax and behaviors for file operations. The specification mandates support for options such as -i, which prompts the user interactively before overwriting an existing destination file, ensuring safe handling of potential during copies. This compliance ensures portability across Unix variants, including Unix, , and BSD derivatives, where cp copies the contents of source files to targets while preserving basic unless otherwise specified. Implementations in distributions commonly use the Coreutils version of cp, which extends functionality with advanced preservation options like --preserve=mode to retain file permissions, --preserve=timestamps for modification and access times, and --preserve=[context](/page/ConTeXt) for SELinux contexts on systems where they are enabled. cp also supports --preserve=all to attempt retaining a comprehensive set of attributes, including and extended attributes, though failures in preservation (such as due to insufficient privileges) do not alter the overall . For hard links, the --preserve=links option ensures that multiple source files linked to the same inode are replicated with identical linking in the destination, maintaining structural integrity. Regarding symbolic links, POSIX requires specific handling during recursive copies (-R): the -H flag dereferences only symbolic links encountered on the command line, -L dereferences all symbolic links during traversal, and -P treats symbolic links as regular files without following them, copying the link itself. In FreeBSD and macOS, which derive from BSD, cp includes these -H, -L, and -P flags as standard extensions to POSIX for link dereferencing, available since the 1990s to support precise control over symlink behavior in hierarchical copies. GNU cp aligns with this via equivalent options: -H for command-line dereferencing, -L for full dereferencing, and -d or --no-dereference to copy symlinks as symlinks. For special files such as device nodes or FIFOs, cp with -R recreates them in the destination rather than copying their contents, preserving their type and attributes as implementation-defined. In , this results in special files being generated anew during recursive operations, without attempting to read their data. cp follows suit by default but provides --copy-contents to explicitly copy the contents of special files as if they were regular files during recursion, though this is generally discouraged for non-regular file types like block devices.

DOS and Windows

The copy command in MS-DOS and the Windows Command Prompt (cmd.exe) is a built-in utility for duplicating one or more files from a source to a destination location, primarily handling individual files rather than entire directory structures. Originating from early MS-DOS versions, it retains compatibility with legacy 8.3 filename conventions while supporting modern features in Windows environments. The general syntax is copy [/d] [/v] [/n] [/y | /-y] [/z] [source] [destination], where key options include /v for verifying that files are written correctly to the destination (introduced in early DOS and carried forward), which performs a byte-by-byte comparison but slows the process, and /d for copying encrypted files (such as those protected by Encrypting File System) as decrypted versions at the destination, a feature available since Windows 2000. Additional flags like /n enable the use of short (8.3) filenames when dealing with long paths, /y suppresses prompts for overwriting existing files, and /z supports restartable copies over networks with progress indication. In Windows, the copy command handles long filenames—introduced with the VFAT filesystem in , allowing paths up to 260 characters (with extensions up to 255)—natively when quoted properly, though it falls back to short names via /n if needed to avoid truncation errors. It also supports UNC (Universal Naming Convention) paths, such as \\server\share\file.txt, for network locations, with /z enhancing reliability during interruptions. However, the command inherits DOS-era limitations, such as not recursively copying directories (requiring xcopy or robocopy for that), and it processes files in binary mode by default unless specified as ASCII with /a. For batch scripting integration, the copy command sets the %errorlevel% to 0 on success and a non-zero value (typically 1) on failure, such as when a source file is missing or access is denied, enabling conditional logic like if errorlevel 1 [echo](/page/Echo) Copy failed. This feature, consistent across and Windows versions, facilitates error handling in automated scripts without additional tools. PowerShell introduces Copy-Item as a .NET-based of the traditional copy command, offering greater flexibility through provider integration (e.g., FileSystem) while maintaining via aliases like copy. Unlike cmd.exe's copy, it supports recursive directory copying with the -Recurse parameter and overrides restrictions (e.g., read-only attributes) using -Force, along with full handling of long filenames and UNC paths in modern Windows environments. This cmdlet returns objects for processing, enhancing scripting capabilities beyond the simple exit codes of its predecessor.

Other Variants

In , the COPY command, introduced with the operating system's initial release in 1977, includes the /PROTECTION (or /PROT) qualifier to explicitly specify user identification code (UIC)-based protection for output files during copying, enabling control over access rights such as system, owner, group, and world permissions rather than relying solely on defaults. This feature supports protection inheritance from source files when not overridden, ensuring consistent security in file operations across VMS environments. Variants of the copy command appear in embedded systems, such as the toybox implementation of cp in the Android shell, which provides a compact, multicall binary with essential options like -p for preserving timestamps and modes, -r for recursive copying, and -f for forcing overwrites, but omits advanced features found in fuller toolsets to suit resource-constrained devices. In real-time operating systems (RTOS) and similar embedded contexts, copy utilities often mirror this minimalism, prioritizing efficiency over extensive flags to handle file transfers without bloating firmware. On mainframe systems like IBM , the TSO/E OCOPY command facilitates copying between datasets—such as sequential datasets or partitioned dataset (PDS/PDSE) members—and z/OS UNIX files, using ddnames for allocation and supporting intra- or intra-shell transfers with optional code page conversion for single-byte data. This adaptation is tailored for management in large-scale environments, allowing specification of source and target via parameters like FROM and TO for precise handling of mainframe storage structures. In Plan 9, the cp command performs file copying with namespace-specific path handling, resolving source and destination paths within the per-process namespace to enable flexible, distributed file operations without global assumptions about file locations. Options like -x preserve source modes and modification times, while multiple-file copies to a directory retain original names, integrating seamlessly with Plan 9's union-mounted, private namespaces that differ from the Unix baseline's fixed global hierarchy.

Differences and Compatibility

Variations Across Systems

The POSIX standard for the cp utility mandates a core set of options, including -R for recursive copying of file hierarchies, -p to preserve file mode, timestamps, ownership, and group, and -i to prompt before overwriting existing files, but it permits implementation-defined behaviors and extensions for additional functionality. This flexibility has resulted in over 20 unique flags across variants, such as GNU Coreutils' --preserve=all for comprehensive metadata retention and --no-clobber to avoid overwrites. A notable inconsistency in flag naming arises with : Unix-like systems use -r or -R to copy directories and their contents , while the DOS and Windows COPY command lacks a native flag, relying instead on the separate utility with /S to include subdirectories (excluding empty ones) or /E for all, including empty. Overwrite policies also differ significantly: In Unix-like implementations like GNU cp, the default behavior is to overwrite existing destination files without prompting if the user has write permission, unless -i is specified for interactive confirmation or -n for no-clobber. Conversely, the Windows COPY command defaults to prompting for confirmation before overwriting an existing file, which can be suppressed with the /Y flag or enabled explicitly with /-Y. Metadata preservation varies widely, with GNU cp supporting --preserve=all to retain file mode, ownership, timestamps, symbolic links, extended attributes, and security context (SELinux labels), enabling comprehensive duplication of file properties. In contrast, the Windows COPY command does not natively preserve access control lists (ACLs) or other advanced metadata, requiring tools like XCOPY with /O for ownership and ACL copying or ICACLS for explicit permission management.

Common Issues and Workarounds

One common issue with the cp command in systems arises when attempting to copy files without sufficient permissions, resulting in a "permission denied" error if the user lacks read access to the source or write access to the destination directory. To resolve this, users can prefix the command with to execute it with elevated privileges, provided they have administrative rights. In contrast, the copy command in Windows and DOS often encounters "access denied" errors due to insufficient privileges on protected files or directories, such as those in system folders. The workaround involves running the Command Prompt as an administrator via the "Run as administrator" option in the or context menu. Path length limitations frequently cause failures in file copying operations across systems. In Windows, the default maximum path length is 260 characters (including the null terminator), leading to errors when copying files with longer paths using the copy command, as it relies on the CopyFileW API function. Enabling long path support via registry modification (setting LongPathsEnabled to 1 under HKLM\SYSTEM\CurrentControlSet\Control\FileSystem) and application manifests allows paths up to 32,767 characters. Unix-like systems, however, support much longer paths, with PATH_MAX typically defined as 4096 characters in Linux, enabling cp to handle extended paths without issue. Cross-filesystem copies can fail when dealing with junctions in Windows, as these directory links are restricted to the same volume and cannot span different drives or network locations; the copy command may either fail or dereference the junction by copying its contents instead of preserving the link. A practical workaround is to use robocopy with flags like /SL (to copy symbolic links as links) or /SJ (for junctions), which replicates the link structure without following it. In Unix-like environments, similar issues with symbolic links can be addressed using rsync with the -l option to preserve links during cross-filesystem transfers. Error handling varies between systems, affecting scripting and . The cp command in systems returns an of 0 for success and 1 (or another nonzero value) for failures, such as permission errors or nonexistent files, allowing scripts to check $? for conditional logic. Conversely, the copy command in DOS and Windows sets %ERRORLEVEL% to 0 on successful copies and 1 for failures like invalid sources or parameters, enabling batch files to evaluate it with IF ERRORLEVEL.

References

Add your contribution
Related Hubs
Contribute something
User Avatar
No comments yet.