For decades, Linux users have been renaming files with the mv command. It\u2019s easy, and the command does just what you expect. Yet sometimes you need to rename a large group of files. When that is the case, the rename command can make the task a lot easier. It just requires a little finesse with regular expressions.\n\nUnlike the mv command, rename isn\u2019t going to allow you to simply specify the old and new names. Instead, it uses a regular expression like those you'd use with Perl. In the example below, the "s" specifies that we're substituting the second string (old) for the first, thus changing this.new to this.old.\n$ rename 's\/new\/old\/' this.new\n$ ls this*\nthis.old\n\nA change as simple as that would be easier using mv this.new this.old, but change the literal string \u201cthis\u201d to the wild card \u201c*\u201d and you would rename all of your *.new files to *.old files with a single command:\n$ ls *.new\nreport.new schedule.new stats.new this.new\n$ rename 's\/new\/old\/' *.new\n$ ls *.old\nreport.old schedule.old stats.old this.old\n\nAs you might expect, the rename command isn\u2019t restricted to changing file extensions. If you needed to change files named \u201creport.*\u201d to \u201creview.*\u201d, you could manage that with a command like this:\n$ rename 's\/report\/review\/' *\n\nThe strings supplied in the regular expressions can make changes to any portion of a file name \u2014 whether file names or extensions.\n$ rename 's\/123\/124\/' *\n$ ls *124*\nstatus.124 report124.txt\n\nIf you add the -v option to a rename command, the command will provide some feedback so that you can see the changes you made, maybe including any you didn\u2019t intend \u2014 making it easier to notice and revert changes as needed.\n$ rename -v 's\/123\/124\/' *\nstatus.123 renamed as status.124\nreport123.txt renamed as report124.txt\n\nOn the other hand, using the -n\u00a0(or --nono) option makes the rename command tell you the changes that it would make without actually making them. This can save you from making changes you may not be intending to make and then having to revert those changes.\n$ rename -n 's\/old\/save\/' *\nrename(logger.man-old, logger.man-save)\nrename(lyrics.txt-old, lyrics.txt-save)\nrename(olderfile-, saveerfile-)\nrename(oldfile, savefile)\nrename(review.old, review.save)\nrename(schedule.old, schedule.save)\nrename(stats.old, stats.save)\nrename(this.old, this.save)\n\nIf you're then happy with those changes, you can then run the command without the -n option to make the file name changes.\nNotice, however, that the \u201c.\u201d within the regular expressions will not be treated as a period, but as a wild card that will match any character. Some of the changes in the examples above and below are likely not what was intended by the person typing the command.\n$ rename -n 's\/.old\/.save\/' *\nrename(logger.man-old, logger.man.save)\nrename(lyrics.txt-old, lyrics.txt.save)\nrename(review.old, review.save)\nrename(schedule.old, schedule.save)\nrename(stats.old, stats.save)\nrename(this.old, this.save)\n\nTo ensure that a period is taken literally, put a backslash in front of it. This will keep it from being interpreted as a wild card and matching any character. Notice that only the \u201c.old\u201d files are selected when this change is made.\n$ rename -n 's\/.old\/.save\/' *\nrename(review.old, review.save)\nrename(schedule.old, schedule.save)\nrename(stats.old, stats.save)\nrename(this.old, this.save)\n\nA command like the one below would change all uppercase letters in file names to lowercase except that the -n option is being used to make sure we review the changes that would be made before we run the command to make the changes. Notice the use of the \u201cy\u201d in the regular expression; it\u2019s required for making the case changes.\n$ rename -n 'y\/A-Z\/a-z\/' W*\nrename(WARNING_SIGN.pdf, warning_sign.pdf)\nrename(Will_Gardner_buttons.pdf, will_gardner_buttons.pdf)\nrename(Wingding_Invites.pdf, wingding_invites.pdf)\nrename(WOW-buttons.pdf, wow-buttons.pdf)\n\nIn the example above, we're changing all uppercase letters to lowercase, but only in file names that begin with an uppercase W.\nWrap-up\nThe rename command is very helpful when you need to rename a lot of files. Just be careful not to make more changes than you intended. Keep in mind that the -n (or spelled out as\u00a0--nono) option can help you avoid time-consuming mistakes.