Lesson 8 of 17

Copying Files

Duplicating Files

cp (copy) copies files from one location to another. The original file is unchanged.

Basic Syntax

cp source destination

Copying a File to a New Name

cp hello.txt hello-copy.txt

This creates hello-copy.txt with the same content as hello.txt.

Copying into a Directory

If the destination is an existing directory, the file is copied into it:

cp hello.txt docs/

This creates docs/hello.txt.

Copying Directories

By default, cp refuses to copy directories. Use -r (recursive) to copy a directory and all its contents:

cp -r docs/ docs-backup/

Useful Flags

FlagMeaning
-rRecursive — copy directories
-vVerbose — show what's being copied
-iInteractive — ask before overwriting

Your Task

Copy hello.txt to a new file called hello-copy.txt, then list the directory to confirm both files exist.

Linux shell loading...
Loading...
Click "Run" to execute your code.