cp
The command that copies files, and with -R whole directory trees.
It replaces an existing destination file without asking unless -i or -n is given.
In more detail
Sources come first and the destination last; if the last argument is an existing directory, the copies go inside it. cp silently overwrites an existing destination unless you add -i to be asked or -n to never overwrite. -p keeps the original times and permission modes.
Examples
cp report.txt notes.txt archive/cp -R project/ project-backup/cp -r cookbook cookbook-copy (the copy includes .git, so it has the whole history)Related terms
- mv — The command that moves files and directories, which is also how you rename them.
- rm — The command that deletes files, and with -r whole directory trees, permanently.
- recursive option — A command option, usually -r or -R, that makes the command act on a directory and everything inside it, all the way down.
Taught in
- Making, Copying, Moving And Removing — Bash Scripting & Command Line Automation
- Redirection: Truncate, Append, Both Streams — Bash Scripting & Command Line Automation
- trap, Cleanup And Temporary Files — Bash Scripting & Command Line Automation
- Permissions And Ownership — Bash Scripting & Command Line Automation
- Archives, Transfers And The Network — Bash Scripting & Command Line Automation
- Upgrading For CVEs: Read The Feed, Then Patch — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Seccomp: Which Syscalls A Container May Make — Certified Kubernetes Security Specialist (CKS) Exam Prep
- A Repository Is A Folder With A Memory — Advanced Git Internals & Distributed Workflows
- Logins, su, sudo And SSH Between Hosts — Red Hat Certified System Administrator (EX200) Exam Prep
- Exam-Style Scripts: Arguments, Output And Exit Codes — Red Hat Certified System Administrator (EX200) Exam Prep
- SELinux Contexts: Labels, restorecon And Rules That Last — Red Hat Certified System Administrator (EX200) Exam Prep
- Forbidden, With Perfect Permissions: Paths, ACL Masks And SELinux Denials — CompTIA Linux+ (XK0-006) Exam Prep
- Files: Globs, Copies And Compression — LPIC-1 Linux Administrator (101-500 and 102-500) Exam Prep
- Git And VS Code: Clone, Commit, Push, And The Dev Container — RHCE in Ansible (EX294): Automate Red Hat Systems
References
Certification courses
- CKS course and practice exam: Certified Kubernetes Security Specialist
- RHCSA course and practice exam: Red Hat Certified System Administrator (EX200)
- CompTIA Linux+ course and practice exam: XK0-006
- LPIC-1 course and practice exam: Linux Administrator (101-500 and 102-500)
- RHCE course and practice exam: Red Hat Certified Engineer in Ansible (EX294)