HowTo: Unix / Linux Rename File Extension From .OLD to .NEW

How do I rename a file called resume.docz to resume.doc? I would like to rename a .txt file as .doc file. How do I rename a file called foo.txt to foo.doc under Linux / Unix / Apple OS X / *BSD operating systems using the command prompt?

You need to use mv command. The syntax is as follows:

ADVERTISEMENTS

mv old-file-name new-file-name

To rename a file called resume.docz to resume.doc, run:

mv resume.docz resume.doc
ls -l resume.doc

To rename file extension from .txt to .doc, enter:

mv foo.txt foo.doc
ls -l foo.doc
## error ##
ls -l foo.txt

To fix the extension of all your .txt files, enter::

rename .txt .doc *.txt

The above command will rename all *.txt files to *.doc i.e. fix the extension of your txt files.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 comments… add one
  • Robinson Apr 1, 2014 @ 12:38

    How to rename multiple file with a single cmd …

  • AGG Apr 20, 2016 @ 12:01

    “rename .txt .doc *.txt” was great command . Thank you

  • Alex Nov 6, 2016 @ 10:35

    hello

    I have missed up my photos directory,
    how can I rename all files
    07.jpg.13 07.jpg.14 07.jpg.15 ……..

    to the correct format
    07-13.jpg 07-14.jpg 07-15.jpg …..

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.