Use cp source destination to copy a file, and cp -R source_dir destination_dir to copy a directory tree. The examples below use GNU cp on Linux unless noted; Unix-like systems can differ, especially in their options and symbolic-link behavior.
Copy one file or several files
With two operands, cp copies the source to the destination. If the destination name does not exist, it becomes the copied file’s name; if it is an existing directory, the source is copied into that directory under its original name.
# Copy a file under a new name
cp report.txt report-copy.txt
# Copy a file into an existing directory
cp report.txt backups/
# Copy several files into an existing directory
cp report.txt notes.txt backups/
When you supply multiple source files, the destination must be a directory. GNU documents these forms in its cp invocation manual.
Copy a directory and its contents
By default, GNU cp does not copy directories. Add -R (recursive) to copy a directory tree, including its contents:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minutecp -R project/ project-backup/
-R is the clearest choice for recursive copying. GNU also accepts -r, but warns that its behavior for symbolic links and special files is not portable. POSIX notes that implementations may dereference symbolic links during recursive copying unless link handling is specified. Check the local manual when a command must behave consistently across different Unix systems; see the POSIX cp manual page.
Choose how symbolic links are handled
In GNU cp, copying a symbolic link as a single-file source normally follows the link and copies the file it points to. During recursive traversal, encountered symbolic links are normally copied as links. These are GNU defaults, not a guarantee for every Unix implementation.
-L: follow source symbolic links.-P: preserve source symbolic links rather than following them.-H: follow command-line symbolic links, but not links encountered while traversing a directory tree.
For example, use cp -R -L tree/ tree-copy/ when you want GNU cp to follow links encountered in the source tree. Use cp -R -P tree/ tree-copy/ to preserve those links. If you specify conflicting link options, GNU says the last one takes effect. Consult your system’s manual before relying on these options outside GNU/Linux.
Rank #2
- The Unix Programming Environment (Prentice-Hall Software Series)
- Product Type: ABIS_BOOK
- Pearson
Prevent accidental overwrites
A copy can replace an existing destination file. GNU cp provides -i to prompt before overwriting:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
cp -i report.txt backups/
GNU also documents -n to skip existing files, but notes that it is deprecated because exit-status behavior differs across platforms. For an important copy, inspect the destination first or use the interactive prompt. GNU cp normally refuses to copy a file onto itself and refuses a dangling destination symlink by default; setting POSIXLY_CORRECT changes the latter behavior.
Preserve metadata when needed
For a recursive GNU/Linux copy that attempts to retain links and broad file attributes, use archive mode:
Rank #3
- Used Book in Good Condition
cp -a project/ project-backup/
GNU defines -a as equivalent to -dR --preserve=all, with reduced diagnostics. It attempts broad preservation, but cannot guarantee that every attribute survives: permissions, filesystem support, and differences between ACL formats can matter. For a narrower request, -p asks GNU cp to preserve mode, ownership, and timestamps where possible.
Make the destination explicit in GNU scripts
GNU cp supports -t DIR (or --target-directory=DIR) to specify the destination directory before the sources. This can make scripts with multiple source paths easier to read:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →cp -t backups/ report.txt notes.txt
GNU’s -T (or --no-target-directory) treats the final operand as a normal destination rather than automatically treating it as a directory. These are GNU options; verify availability before using them on another implementation.
Rank #4
Advanced GNU option: copy on write
GNU cp --reflink=auto source destination can request a lightweight copy-on-write copy when the filesystem supports it. The files may share data blocks until one is changed. GNU warns that an I/O error affecting shared blocks can affect both files, so this is an advanced filesystem-dependent option, not a substitute for an independent backup.
Quick option reference
| Task | GNU option | What it does |
|---|---|---|
| Copy directories recursively | -R / --recursive |
Copies a directory tree. |
| Recursively copy and attempt broad preservation | -a / --archive |
Requests recursive copying and preservation of links and attributes where possible. |
| Preserve basic metadata | -p |
Attempts to preserve mode, ownership, and timestamps. |
| Prompt before overwriting | -i |
Asks before replacing an existing destination. |
| Follow source symbolic links | -L |
Follows links when copying. |
| Preserve source symbolic links | -P |
Copies links as links. |
| Set destination directory explicitly | -t DIR |
Places the source files in the named directory. |
Long-option names and some edge-case behavior are specific to GNU cp. For portability, check the manual on the system where the command will run.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.

