How to Rename Files in Linux (3 Methods)
In the Linux system, there are several commonly used methods to modify file names.
- The mv command is used for moving or renaming files in Linux. It is the most commonly used method for renaming files, with the format being mv old_file new_file.
- You can use the rename command to batch rename file names. The syntax is rename ‘s/old_pattern/new_pattern/’ file(s).
- Use the cp and rm commands: start by copying the file using the cp command and specifying a new file name, then delete the original file using the rm command.
- With the sed command, you can edit text files and also rename files by using the syntax sed ‘s/old_pattern/new_pattern/’.
- By using a shell script, you can write a script to batch modify file names, for example by using a for loop to iterate through a file list, and then using the mv command to change the file names.
These are some common methods to choose from for modifying file names based on your own needs.