Home Miscellaneous File rename command

File rename command

by SupportPRO Admin

Its a perl-based command. It can we used to rename a file or multiple ones.
General Syntax ::
——-
rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]
-v :: means “verbose”
-n  :: testing mode will show the output of command without modifying the file names.
perlexpr :: part of the command is a perl expression
Example ::
rename -n ‘s/\.htm$/\.html/’ *.htm

The -n means that it’s a test run and will not actually change any files. It will list the output .

If the output of the above test run looks okay, then you could run the final command:

rename -v ‘s/\.htm$/\.html/’ *.htm

Explanation ::

“s” means substitute. The syntax is s/old/new/ substitute the “old” with the “new”.

\. >> “.” (period) it may read as special character.  backslash can we used to make it read as normal character.

.htm$ >> “$” means the end of the string. \.htm$ means that it will match .htm but not .html.

*.htm >> “*” is a wildcard used here to select all the files with extension .htm.

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value

Leave a Comment