How to Rename a file using Mac Terminal

In order to rename a file using Mac Terminal make use of the mv (move) command.


Suppose I have a file name myfile.txt on the Mac Desktop and I want to rename it to myfile_2020.txt then below are the steps,

  1. Open Mac Terminal,
  2. Move to the Desktop: cd ~/Desktop
  3. Now to rename the file run the mv command,

    mv current-file-name new-file-name
    % mv myfile.txt myfile_2022.txt
  4. The file will be renamed with myfile_2022.txt
Rename file using Mac Terminal using mv Command
Before renaming the file
Before renaming the file
After renaming the file
After renaming the file

Have Questions? Post them here!
Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.