Click the virtual machine below to start practicing
>_ Tekhnikum | Lab
Setting up virtual machine…
Preparing lab files…
Starting terminal services…
This lab machine has stopped
Your progress through the guide is saved. Start a fresh machine to keep practicing.
Introduction
cp copies files and directories; the original stays where it is. ~/project has files to copy and the folders Documents, Pictures and backups to copy them into.
This lab is the hands-on companion to the cp (Copy) lesson from Linux Journey (CC BY-SA 4.0).
Copy a File into a Directory
The last argument is the destination:
cp mycoolfile Documents/
ls Documents
Copy Under a New Name
If the destination is a file name, the copy gets that name:
cp mycoolfile Documents/mycoolfile_backup
Copy Many with a Wildcard
*.jpg matches every name ending in .jpg. Preview the match with ls first, then copy:
ls *.jpg
cp *.jpg Pictures/
Copy a Whole Directory
cp skips directories unless you add -r (recursive), which copies everything inside:
cp -r Pumpkin backups/
ls -R backups
Summary
cp source dir/ copies a file into a directory.
cp source newname copies under a new name.
Wildcards like *.jpg copy many files; preview with ls first.
cp -r copies directories and everything inside them.