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

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.

Usage:cpsourcedestination
cp
Copy file - duplicates a file to a new location or name.

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.

Usage:cp-rsource_dirdest_dir
-r
Recursive - copies directories and all files within them.

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.

Usage:cpfile.txtdirectory/
directory/
Target directory - keeps original filename inside the directory.

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 Microsoft Learn and Windows 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.