How to Copy Files and Directories with the Linux cp Command

Published 2026-08-05 · Learn Linux

The cp command copies files and directories. The basic form is cp source destination, so cp notes.txt notes-backup.txt creates a copy of notes.txt. Copying a folder needs an extra flag, which trips up beginners — this guide covers it.

Copy a single file

Give cp a source file and a destination. The destination can be a new file name or an existing directory.

$ cp notes.txt notes-backup.txt
$ cp notes.txt backups/

Copy a directory with -r

Copying a directory with a plain cp fails with the message omitting directory. Add -r (recursive) to copy the folder and everything inside it.

$ cp -r projects projects-backup

Keep permissions with -p

By default cp sets the copy's permissions to your default umask. Use -p to preserve the original permissions, ownership and timestamps, which matters when backing up config files.

$ cp -p /etc/hosts hosts.bak

Never overwrite with -n

cp silently overwrites an existing destination file. Add -n to skip files that already exist, or -i to be asked before each overwrite.

$ cp -n data.csv archive.csv
$ cp -i data.csv archive.csv

Copy like a pro

Combine flags in one short call. cp -rva copies recursively, preserves everything, prints each file as it goes, and is the workhorse for moving a site or project folder.

$ cp -rva /var/www/site /var/www/site.bak

To sync folders across machines instead, see rsync. The cp reference page lists every flag.

Keep learning

Related guides: The Linux ls Command: List Files Like a Pro · How to Find Files and Directories with the Linux find Command · Linux chmod Command: A Complete Permissions Guide. Read all tutorials on the Learn Linux blog.