How to Rename Files in UNIX / Linux

The most straightforward way to rename a file in UNIX/Linux is using the mv command. Simply type mv old_filename new_filename to rename your file.

Use the mv Command

For renaming files in different directories, use absolute paths. Example: mv /home/user/oldfile.txt /home/user/newfile.txt to rename along with changing the file's location.

Renaming Files with Absolute Paths

Need to rename multiple files? The mv command can be used in loops or bash scripts to rename files in bulk.

Bulk Renaming Using Scripts

The rename command is excellent for renaming multiple files. To change all .txt files to .md, use: rename 's/.txt/.md/' *.txt.

Batch Renaming with rename Command

To rename files spread across multiple directories, combine the find command with mv or rename for more complex file renaming tasks.

Use find Command for Files in Multiple Directories

For more tips and expert advice on mastering Linux commands and administration, visit unixmen.com—your go-to resource for all things Linux!

Learn More at unixmen.com