Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

How to Rename a File in Linux: mv, rename, and git mv

Sean

Platform Writer

Jul 05, 2026
4 min read

How to rename a file in Linux: mv oldname newname for single files (also moves between directories). For batch renames, use rename 's/old/new/' *.txt (Perl-based) or shell loops. For git-tracked files, use git mv to keep git history clean. The team that uses mv for single, rename for batch, and git mv for tracked files has the right tool for each.

How to Rename a File in Linux: mv, rename, and git mv

Table of contents

mv command

Single file:

mv oldname.txt newname.txt

Same command moves between directories:

mv file.txt /path/to/destination/
mv /path/to/file.txt /new/path/newname.txt

The team that uses mv for single renames has the standard tool.

rename (batch patterns)

For multiple files, use rename (Perl-based, available via perl package):

# Rename all .txt to .md
rename 's/\.txt$/.md/' *.txt

# Add prefix
rename 's/^/old_/' *.log

# Replace spaces with underscores
rename 's/ /_/g' *

The team that has 100+ files to rename uses rename.

Shell loop (no rename)

If rename isn’t available:

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

The team that uses shell loops has full control without external dependencies.

git mv (for tracked files)

git mv oldname.txt newname.txt

Same as mv but git tracks the rename. The team that uses git mv has clean git history (no add+delete).

Rename a directory

mv olddir newdir

Same as file rename. The team that renames a directory has both the directory and its contents moved.

Cross-filesystem rename

On the same filesystem, mv is a rename (instant). Across filesystems, it’s copy + delete (slower):

mv /home/file.txt /mnt/external/
# If /mnt is different filesystem: copy + delete

The team that has large files crossing filesystems has slow renames.

Quirks

  1. mv overwrites without confirmation. Use mv -i for interactive.
  2. Spaces in filenames: quote them. mv "old name.txt" "new name.txt".
  3. Hidden files (starting with .): not matched by *. Use mv .hidden .newname directly.

FAQ

Is mv atomic?

On the same filesystem, yes. Across filesystems, no (it’s copy + delete).

What’s the difference between mv and rename?

mv: single file/dir. rename: batch pattern. Use the right tool for the job.

Can I undo a rename?

Not directly. Use git to revert (if tracked). Otherwise, restore from backup.

How do I rename and keep the file in git?

git mv instead of mv. The team that uses git mv has git track the rename as a rename, not add+delete.

What about case-insensitive filesystems?

On macOS (HFS+ default) and Windows, renaming from File to file may be a no-op. On Linux (case-sensitive), it’s a real rename.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#linux#rename#mv#command#dev-infra