- What safety checks should you do before deleting anything from the terminal?
- How is moving a file different from copying it?
M09 - File Operations: Copy, Move, Delete
Copy, move, rename, delete, and archive files safely so you can reorganize work without losing track of what changed.
File Operations: Copy, Move, Delete
Copy, move, rename, delete, and archive files safely so you can reorganize work without losing track of what changed.
- Copy, move, rename, delete, and archive files safely so you can reorganize work without losing track of what changed.
Concept to practice path
Each lesson is meant to move from an idea, to an example, to a safe practice step.
Open the full visualWhy This Matters
These commands are simple, but they change the file system for real.
That is why this lesson is about judgment as much as syntax:
- copy before you risk a change
- confirm the path before you move
- delete only when you are sure
If you build those habits now, the commands stay useful instead of becoming dangerous.
Copy, move, or delete?
1. Copy First
Copying is the safest way to preserve the original while you reorganize or experiment.
Copy one file
Copy-Item .\report.txt .\backup\report.txt
Copy one folder and everything inside it
Copy-Item .\Project .\Project-copy -Recurse
Copy one file
cp ./report.txt ./backup/report.txt
Copy one folder and everything inside it
cp -r ./Project ./Project-copy
If the result matters, list the destination afterward and verify it.
2. Move or Rename
Moving changes where something lives. Renaming changes its label. On the command line, those are often the same command.
Rename in the same folder
Move-Item .\draft.txt .\notes.txt
Move into another folder
Move-Item .\notes.txt .\archive\
Rename in the same folder
mv ./draft.txt ./notes.txt
Move into another folder
mv ./notes.txt ./archive/
When you are learning, move one item at a time first. Bulk moves can wait.
3. Delete With a Checklist
Deletion is not the place for speed.
Use this checklist before you press Enter:
- Am I in the directory I think I am?
- Did I list the target first?
- Am I deleting a practice file, not something important?
- If a wildcard is involved, do I understand exactly what it matches?
Delete one file
Remove-Item .\old-note.txt
Delete one folder and its contents
Remove-Item .\old-project -Recurse
Delete one file
rm ./old-note.txt
Delete one folder and its contents
rm -r ./old-project
Safer Beginner Rule
Do not start with force flags. Learn the plain command first, in a practice folder, and confirm the result after each step.
4. Archive for Transfer or Backup
Sometimes you need one file that represents a whole folder.
Compress-Archive -Path .\Project -DestinationPath .\Project.zip
tar -czvf Project.tar.gz ./Project
Archives help when you want to transfer, back up, or snapshot a directory.
A Reliable Practice Pattern
In a practice directory:
- Create a file.
- Copy it to a backup name.
- Rename the original.
- Remove only the backup copy.
- Archive the folder.
That sequence teaches more than memorizing flags.
What to Ignore for Now
- hard links and symbolic links
- destructive force flags by default
- advanced archive options
Those topics matter later, but they are not required for safe first use.
Before You Move On
You are ready when you can explain, in your own words:
- why copying is safer than moving when you are unsure
- how renaming uses the same move command
- why deletion requires an explicit check step
- why archives are useful
Next, we focus on finding programs and files when you do not remember where they live.
Recall it, check it, then practice it.
Do this before moving on. It turns reading into memory and safer action.
- Copy one file, rename another, and remove a practice file without deleting the wrong target.
- Create one archive from a folder and explain why that can be useful.
Review again after 1, 3, 7 days.
What to do next
Best next step PracticeUse the matching lab or keep building skill in practice.