How can we batch rename files in CentOS?
To batch rename files on CentOS, you can use the following command:
- Switch to the directory containing the file you want to modify using the cd command. For example, if the file you want to modify is located in /home/user/directory, you can use the following command to navigate to that directory:
cd /home/user/directory
- Batch modify file names using the following command:
rename 's/旧文件名/新文件名/' *
In the command above, replace “old filename” with the common part of the file name to be modified (e.g. to change “file1.txt” to “newfile1.txt”, you can replace “old filename” with “file”), and replace “new filename” with the new file name (e.g. “newfile”). The asterisk (*) in the command will match all files in the directory. If you want to limit the matching file types, you can use wildcards (e.g. .txt, *jpg, etc).
- After running the command, the file names will be updated in bulk to the new ones.
Please note that the command above is using the default rename command in CentOS. If this command is not available on your system, you can try using alternative options such as mmv or prename.