CMD Master
Back to Blog
Arnošt Havelka

Copying Files and Directories

Master cp to copy files and recursive directory structures.

Start Interactive Lesson
Copying Files and Directories

The cp command copies files and directories. It's essential for backing up and duplicating your work.

Copy a Single File

Use cp source destination to copy a file.

Try the command

Copy a file!

Build the command
cpsourcedestination
Choose a command
Terminal
C:\Users\User>cp file.txt file_backup.txt

Duplicate a file:

Command Prompt
original.txt
C:\Users\User>ls

Recursive Copy: cp -r

The -r flag copies entire directories with all their contents.

Try the command

Copy entire directories!

Build the command
cp-rsource_dirdest_dir
Choose a command
Terminal
C:\Users\User>cp -r Documents Documents_backup

Duplicate folder structures:

Command Prompt
project/
C:\Users\User>ls

Copy to Directory

Copy a file into an existing directory by using the directory as the destination.

Try the command

Copy file into a folder!

Build the command
cpfile.txtdirectory/
Choose a command
Terminal
C:\Users\User>cp file.txt ~/Documents/

Place file in folder:

Command Prompt
file.txt Archive/ ls Archive/
C:\Users\User>ls

Knowledge Check

1 / 3

What does cp do?

References

These documentation links provide authoritative details for the commands used in this article.

Up Next

Moving and Renaming Files

Use mv to move files between directories and rename them.