How to Copy a File in the Terminal with cp
You have one important file, and you want to change something in it. But a small fear stops you: what if you mess up the whole thing? Most of us have felt this. Today we fix it with one tiny habit.
To copy a file in the terminal, use the cp command: type cp, then the original file name, then the new name you want for the copy. For example, cp a.txt b.txt creates a second file called b.txt while leaving a.txt exactly as it was.
What does it mean to copy a file in the terminal?
Copying a file means making a second version of it. Instead of editing the original, you create a duplicate and play with that one. Now you have two files: the safe one, and one you can experiment on freely.
Think of forwarding a file to two different WhatsApp groups. The same file now exists in two places, and the first one is still right there. Nothing was taken away from you. You simply made a copy. That is exactly what cp does in the terminal.
How do I use the cp command?
The command has three small parts. Let’s break it apart.
cpjust means “copy”.- The first name is the original, the file you already have.
- The second name is the new copy you want to create.
So if you have a file called a.txt and you want a copy called b.txt, you type:
cp a.txt b.txt
Press Enter, and it’s done. You now have both files sitting in the same folder.
Why does copying a file matter?
Because mistakes happen to everyone. With a copy in hand, a mistake costs you nothing. You can edit the copy as boldly as you like, and the original stays safe and untouched.
This is a tiny habit that saves you again and again. Before you change anything important, make a copy first. It takes one second and removes the fear. As you move into bigger tools later in the free Zero to AI Hero course, that same “copy before you change” instinct keeps your work safe.
How do I try this right now?
The best way to learn is to do it. Open your terminal and follow along:
- Pick any file you already have.
- Type
cp, then its name, then a new name. - Press Enter.
- List the folder with
lsto see two files.
If you have not yet learned how to look at what’s in a folder, the earlier lesson on listing folder contents walks you through it step by step. Seeing both files appear is proof that your copy worked.
What comes next after copying?
Once you are comfortable making copies, the natural next step is moving and renaming files with the mv command. Where cp leaves the original in place, mv picks a file up and moves or renames it. Together, cp and mv give you full control over your files from the terminal.
Key takeaways
- Copy a file in the terminal with the
cpcommand:cp original.txt copy.txt. - The first name is the file you have; the second name is the copy you want to create.
- Copying never removes the original, so you keep both files safe.
- Make a copy before editing anything important. It costs one second and removes the fear of breaking things.
- Run
lsafterwards to confirm both files exist. - Next up: moving and renaming files with
mv.
Want to go from “what’s a file?” all the way to building real apps with AI? Follow along with the free Zero to AI Hero course, one short lesson at a time.
🚀 Take the full free course: Zero to AI Hero — learn to build with AI from scratch. New lessons daily, in Hindi & English.
Want to actually learn this?
151 free 2-minute lessons — from "what's a file?" to building with AI.
▶ Start the free course