Hone

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.txt
A draft.
mv draft.txt final.txt
Renamed.
ls
final.txt only.
mkdir done && mv final.txt done/
Moved into a folder.
ls done
final.txt is there now.

Your turn

Rename report.txt to report-2026.txt.

 report.txt report-2026.txt

The trap

mv onto a name that exists replaces that file silently. There is no trash can on the command line.

Next in Terminal

Every Terminal lesson on one page

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.