To rename the file extension of a file in Unix or Linux systems, you can use the mv
command with the rename
utility. The rename
utility allows you to specify a pattern to match the file names you want to rename, and a replacement pattern to use for the new file names.
For example, to rename all files with the .OLD
extension to .NEW
, you can use the following command:
rename 's/\.OLD$/\.NEW/' *
This will rename all files in the current directory that have the .OLD
extension to .NEW
. The *
wildcard character is used to match all files in the current directory.
You can also use the rename
utility to rename files in a specific directory by specifying the directory path. For example:
rename 's/\.OLD$/\.NEW/' /path/to/directory/*
This will rename all files in the /path/to/directory
directory that have the .OLD
extension to .NEW
.
It is important to be careful when using the rename
utility, as it can rename multiple files at once, and there is no way to undo the changes. It is always a good idea to test the command with a small number of files before running it on a large number of files to ensure that it is working as expected.
For more information about the rename
utility and its options, you can consult the documentation for your specific Unix or Linux system.