Online Linux Terminal Logo
OnlineLinuxTerminal
File OperationsCLI Reference

$cp

Copy files and directories to a destination path.

Syntax DefinitionPOSIX standard
cp [OPTIONS] SOURCE... DEST
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `cp` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

Overview & How cp Works

`cp` (Copy) duplicates files or folders from a source to a destination. It supports copying single files, multiple files into target directories, and recursive directory tree replication with preservation of file modes and timestamps.

Common Flags & Command Options

Flag / OptionDescription
-r, -RCopy directories and their contents recursively.
-pPreserve specified attributes like mode, ownership, and timestamps.
-aArchive mode (same as -dR --preserve=all) for exact backups.
-uCopy only when the SOURCE file is newer than the destination file.
-vVerbose output showing files as they are copied.

Practical Real-World Examples

Example #1Create a backup copy of a configuration file
cp welcome.txt welcome.txt.bak && ls -l

Duplicates welcome.txt into welcome.txt.bak in the same directory.

Sample Output:
-rw-r--r-- 1 user user 482B welcome.txt -rw-r--r-- 1 user user 482B welcome.txt.bak

Frequently Asked Questions

What is the best flag to back up an entire folder preserving permissions?

Use `cp -a [source] [destination]` (Archive mode) to preserve permissions, ownership, symlinks, and timestamps.