🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

📁 File Management March 16, 2026 8

Linux Command: cp

Copy files and directories

Terminal — File Management
Command
$ cp report.pdf /home/user/Documents/
Output
Copies report.pdf to the Documents directory.

The cp command copies files and directories from one location to another. It is one of the fundamental file management commands in Linux, used daily by system administrators and developers. cp can copy single files, multiple files, or entire directory trees. It supports preserving file attributes like permissions, timestamps, and ownership during the copy operation. The command can also create hard or symbolic links instead of actual copies. When copying to an existing file, cp overwrites the destination by default. Use the -i flag for interactive mode to get a confirmation prompt before overwriting.

Syntax

cp [OPTION]... SOURCE... DESTINATION

Common Examples

  • cp report.pdf /home/user/Documents/ — Copies report.pdf to the Documents directory.
  • cp config.yml config.yml.bak — Creates a backup copy with a different name in the same directory.
  • cp -r /var/www/html /backup/www-backup — Copies the entire directory tree including all subdirectories and files.
  • cp -a /etc/nginx/ /backup/nginx-config/ — Archive mode preserves permissions, ownership, timestamps, and symlinks.

Pro Tips

    Master this and 230+ other Linux commands with our comprehensive eBooks and cheat sheets.

    Share this tip