Skip to content
SimpleConvertSimpleConvert

Linux cp Command

Copying with cp: recursive copies, preserving attributes, avoiding accidental overwrites, and the trailing-slash trap that catches everyone once.

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

How to use it

  • The synopsis at the top shows the general form of the command.
  • Click any example to copy it straight to your clipboard.
  • The options table lists only the flags worth remembering — run man for the exhaustive list.

Examples

cp file.txt backup.txtcopy a single file
cp -r src/ dest/copy a directory and everything in it
cp -a src/. dest/copy contents, preserving all attributes

Questions people ask

What is the difference between cp -r and cp -a?

-r recurses but resets ownership and timestamps to the copying user and now. -a recurses and preserves them, which is what you want for backups.

How do I stop cp overwriting things?

-n skips existing files silently, -i asks first. Neither is the default, so a plain cp will overwrite without warning.

Does this page work offline?

Yes, after the first visit. The whole reference is part of the page and the service worker caches it.

Runs entirely in your browser. Nothing you type is uploaded, logged or shared.

Last updated 22 August 2026