Software & OS

How to Rename a File on Windows, Mac and Linux

To rename a file on Windows, select it and press F2, type the new name, and press Enter. On a Mac, select it in Finder and press Return instead; on Linux or in any Terminal, run mv old-name new-name.

The sections below cover each system, the command-line versions, renaming many files at once, and the errors you are most likely to hit. Keep the file extension (the part after the last dot) unless you mean to change the file type.

How to rename a file on Windows

In File Explorer, use either of these:

  1. Select the file and press F2. Microsoft's shortcut list describes F2 as "Rename the selected item."
  2. Or right-click the file and choose Rename. In Windows 11 the Rename option is one of the icons at the top of the right-click menu.

Type the new name and press Enter. Leave the extension (the part after the last dot) as it is unless you want to change the file type.

Rename a file in Command Prompt

The rename command (shortened to ren) takes the current name and the new name:

ren report.txt report-final.txt

Put quotes around names that contain spaces:

ren "old report.txt" "new report.txt"

You can't give a new drive or path as the second argument. Per Microsoft's documentation, rename cannot move files to another directory or drive. If the new name already exists, you get Duplicate file name or file not found.

Rename a file in PowerShell

Use Rename-Item (aliases ren and rni):

Rename-Item -Path "C:\work\daily_file.txt" -NewName "monday_file.txt"

-NewName takes a name only, not a path. If you supply a different folder, PowerShell refuses and reports that it can't rename because the target is a path or device name. Use Move-Item when you want to rename and move in one step. Rename-Item also won't overwrite an existing file; even -Force cannot replace the item at the destination name. Add -WhatIf to see what a command would do without running it.

How to rename a file on a Mac

Apple's steps for one item in Finder:

  1. Select the file and press Return. (You can also force click its name.)
  2. Type the new name.
  3. Press Return again.

macOS does not allow a colon (:) in a name, and a name can't begin with a period. Apple also notes that some apps don't allow a slash (/) in file names. Changing the extension, for example .jpg, may leave you unable to open the file with the app that created it.

In Terminal, mv works the same way as on Linux (next section).

How to rename a file on Linux (and in the Mac Terminal)

On Linux, renaming is a move to a new name in the same folder:

mv old-name.txt new-name.txt

The mv manual page describes it as "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY." Quote names with spaces:

mv "old name.txt" "new name.txt"

mv overwrites an existing file with the new name without asking, unless you tell it otherwise. Three options control that:

OptionWhat it does
-iPrompts before overwriting an existing file
-nNever overwrites an existing file
-vPrints what it did

If you pass more than one of -i, -f and -n, only the last one takes effect. A safe habit is mv -iv old.txt new.txt. Example output:

renamed 'old.txt' -> 'new.txt'

Linux commands are case sensitive: Report.txt and report.txt are different files. For other everyday commands, see basic Linux commands.

How to rename multiple files at once

Mac (Finder)

Select the files, Control-click one of them, and choose Rename. Under Rename Finder Items, choose whether to replace text, add text, or change the name format, then click Rename.

Windows (Command Prompt)

Wildcards work in both names. To change every .txt extension in the current folder to .doc:

rename *.txt *.doc

Wildcards in the new name match by position, so results can surprise you. Microsoft's example: rename img*.jpg photo*.jpg turns img001.jpg into photo1.jpg, because photo is longer than img and overwrites the first characters of the old name. The replacement text must be the same length as the text it replaces. To add an extension on the end, rename *.log *.log.bak keeps the old name and appends .bak.

Windows (PowerShell)

Pipe the files into Rename-Item and build each new name in a script block. This is the example from Microsoft's documentation, which renames all .txt files to .log:

Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace '.txt','.log' }

The -replace operator uses a regular expression, and the dot in .txt matches any character, so for names like my-txt-notes.txt use a stricter pattern such as '\.txt$'. Add -WhatIf to the Rename-Item part first to preview the changes.

Linux and Mac Terminal

mv does not accept wildcards in the new name, so use a loop in the shell. This renames every .txt file in the current folder to .md:

for f in *.txt; do mv -i -- "$f" "${f%.txt}.md"; done

${f%.txt} removes the trailing .txt from the name, and -- stops a file name that starts with a dash from being read as an option. Run echo mv -- "$f" "${f%.txt}.md" in place of the mv first if you want to see the commands before running them.

Why you can't rename a file

  • The name already exists. Command Prompt reports Duplicate file name or file not found, and Rename-Item will not replace an existing item. Choose another name or rename the other file first.
  • The name uses a character the system rejects. A colon is not permitted on a Mac, and a name can't begin with a period there.
  • You are trying to move and rename together in PowerShell. Rename-Item accepts a name only. Use Move-Item for a different folder.
  • The file is hidden or read-only (PowerShell). Microsoft says -Force lets Rename-Item rename hidden or read-only files, though it can't override security restrictions.

If you renamed something by mistake, rename it back to the original name.

Frequently asked questions

What is the keyboard shortcut to rename a file?
On Windows, select the file in File Explorer and press F2, type the new name, then press Enter. On a Mac, select the file in Finder and press Return, type the new name, then press Return again.
Can I rename a file without changing its extension?
Yes. Change only the part before the final dot, for example report-draft.docx to report-final.docx. Changing the extension itself, such as .jpg, can stop the original app from opening the file, according to Apple's guidance.
Why can't I rename a file on Windows?
A common cause is that the new name matches a file already in the folder: Command Prompt then reports 'Duplicate file name or file not found', and PowerShell's Rename-Item will not replace the existing item. Pick a unique name. For hidden or read-only files in PowerShell, add -Force.
How do I rename many files at once?
On a Mac, select the files, Control-click one, and choose Rename. On Windows, use Get-ChildItem with Rename-Item in PowerShell, or the rename command with wildcards in Command Prompt. On Linux and macOS Terminal, use a shell for loop around mv.

Sources