Lessons · Terminal · moving and renaming
Moving and renaming are one command
mv old new renames a file. mv file folder/ moves it into the folder. Either way there is one file afterwards, not two.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Renaming a draft to final, moving finished work into a done folder: mv is the tidy-up command.
How to think about it
If the last argument is an existing folder, it is a move into it; otherwise it is a rename to that name.
Worked example
echo x > draft.txtA draft.
mv draft.txt final.txtRenamed.
lsfinal.txt only.
mkdir done && mv final.txt done/Moved into a folder.
ls donefinal.txt is there now.
Your turn
Rename report.txt to report-2026.txt.
report.txt report-2026.txt
Try it at a real prompt
The trap
mv onto a name that exists replaces that file silently. There is no trash can on the command line.
Now you try
Next in Terminal
Practise moving and renaming on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.