File Operations

cp

Copy files and directories from one location to another.

Synopsis

syntax
cp [OPTION]... SOURCE... DEST

Examples

Copy a single file
cp file.txt backup.txt
Recursively copy a directory
cp -r src/ dest/
Copy log files interactively with verbose output
cp -iv *.log /tmp/
Archive copy preserving all attributes
cp -a /data /backup/data

Common options

FlagDescription
-r, -RCopy directories recursively
-iPrompt before overwrite
-vVerbose — explain what is being done
-pPreserve mode, ownership, and timestamps
-uCopy only when source is newer than destination

About cp

The `cp` command copy files and directories from one location to another. File operation commands are essential for navigating and managing the Linux filesystem.

They form the backbone of everyday system administration and development workflows. Mastering these commands enables you to efficiently create, move, copy, and organize files and directories from the terminal, which is often faster and more scriptable than graphical alternatives.

The command accepts 5 commonly used flags shown above, though the full set of options is available in the man page (`man cp`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More File Operations Commands

Other commands in the File Operations category

Related tools